Vancho
Vancho

Reputation: 27

Replace tag with name: xml output

Hello i have some xml output

<?xml version="1.0" encoding="utf-8"?>
<Active-plan currentid="1276215628">
    <Planers>
        <Plan1>
            <package>Intro_Europe_1GB_7d</package>
            <current-package>
                <package currentid="63753939" addid="13000">
                    <group-by-pack>data</group-by-pack>
                    <quantity>1071741824.00</quantity>
                    <remaining>993553024.00</remaining>
                    <timestamp-start>2022-03-01 10:35:05Z</timestamp-start>
                    <timestamp-end>2022-03-08 10:35:05Z</timestamp-end>
                </package>
            </current-package>
        </Plan1>
    </Planers>
</Active-plan>

What i want to have is to have output maybe with SED or AWK

Active plan currentid:1276215628
Package: Intro_Europe_1GB_7d
Package current id:63753939 addit:13000
Group pack : data
Quantity : 1071741824.00
Remaining data : 993553024.00
Start Time : 2022-03-01 10:35:05Z
End time : 022-03-08 10:35:05Z

I think this i need to export with sed and call by echo so i can display in that order that i post (every tag, new line)

Upvotes: 0

Views: 37

Answers (1)

Michael Kay
Michael Kay

Reputation: 163312

XSLT 3.0 solution:

<xsl:transform version="3.0"
   xmlns:xsl="http://www.w3.org/2001/XSL/Transform" 
   expand-text="yes">    
  <xsl:output method="text"/>
  <xsl:template match="/">
    Active plan currentid:{/Active-plan/@currentid}
    Package: {//Plan1/Package}
    Package current id:{//current-package/@currentid} addit:{//current-package/@addit}
    Group pack : {//current-package/group-by-data}
    Quantity : {//current-package/quantity}
    Remaining data : {//current-package/remaining}
    Start Time : {//current-package/timestamp-start}
    End time : {//current-package/timestamp-end}
  </xsl:template>
</xsl:transform>

Solutions using XSLT 1.0 or 2.0 will be a little more verbose but no more difficult.

Upvotes: 2

Related Questions