J
J
I've spent most of the day on this, and I just can't seem to find a
solution, please help me!
I'm recieving XML that I can't modify that looks like:
<?xml version="1.0"?>
<Doc>
<Page>
<Item Value="A" Id="1" Count="1"/>
<Item Value="B" Id="2" Count="1"/>
<Item Value="C" Id="3" Count="1"/>
<Item Value="D" Id="1" Count="2"/>
<Item Value="E" Id="2" Count="2"/>
<Item Value="F" Id="3" Count="2"/>
<Item Value="G" Id="1" Count="3"/>
<Item Value="H" Id="2" Count="3"/>
<Item Value="I" Id="3" Count="3"/>
</Page>
</Doc>
And I need to transform it into:
<Doc>
<Page>
<Line>
<Tag1>A</Tag1>
<Tag2>B</Tag2>
<Tag3>C</Tag3>
</Line>
<Line>
<Tag1>D</Tag1>
<Tag2>E</Tag2>
<Tag3>F</Tag3>
</Line>
<Line>
<Tag1>G</Tag1>
<Tag2>H</Tag2>
<Tag3>I</Tag3>
</Line>
</Page>
</Doc>
But I can't seem to figure out how to create a new "Line" node based on
the count attribute.
Here is XSLT I have now:
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xslutput method="xml" />
<xsl:template match="Doc">
<Doc>
<xsl:apply-templates select="Page"/>
</Doc>
</xsl:template>
<xsl:template match="Page">
<Page>
<Line>
<xsl:for-each select="Item">
<xsl:if test="@Id='1'">
<Tag1><xsl:value-of select="@Value"/></Tag1>
</xsl:if>
<xsl:if test="@Id='2'">
<Tag2><xsl:value-of select="@Value"/></Tag2>
</xsl:if>
<xsl:if test="@Id='3'">
<Tag3><xsl:value-of select="@Value"/></Tag3>
</xsl:if>
</xsl:for-each>
</Line>
</Page>
</xsl:template>
</xsl:stylesheet>
Which only produces:
<Doc>
<Page>
<Line>
<Tag1>A</Tag1>
<Tag2>B</Tag2>
<Tag3>C</Tag3>
<Tag1>D</Tag1>
<Tag2>E</Tag2>
<Tag3>F</Tag3>
<Tag1>G</Tag1>
<Tag2>H</Tag2>
<Tag3>I</Tag3>
</Line>
</Page>
</Doc>
Any help at all is warmly welcomed!
solution, please help me!
I'm recieving XML that I can't modify that looks like:
<?xml version="1.0"?>
<Doc>
<Page>
<Item Value="A" Id="1" Count="1"/>
<Item Value="B" Id="2" Count="1"/>
<Item Value="C" Id="3" Count="1"/>
<Item Value="D" Id="1" Count="2"/>
<Item Value="E" Id="2" Count="2"/>
<Item Value="F" Id="3" Count="2"/>
<Item Value="G" Id="1" Count="3"/>
<Item Value="H" Id="2" Count="3"/>
<Item Value="I" Id="3" Count="3"/>
</Page>
</Doc>
And I need to transform it into:
<Doc>
<Page>
<Line>
<Tag1>A</Tag1>
<Tag2>B</Tag2>
<Tag3>C</Tag3>
</Line>
<Line>
<Tag1>D</Tag1>
<Tag2>E</Tag2>
<Tag3>F</Tag3>
</Line>
<Line>
<Tag1>G</Tag1>
<Tag2>H</Tag2>
<Tag3>I</Tag3>
</Line>
</Page>
</Doc>
But I can't seem to figure out how to create a new "Line" node based on
the count attribute.
Here is XSLT I have now:
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xslutput method="xml" />
<xsl:template match="Doc">
<Doc>
<xsl:apply-templates select="Page"/>
</Doc>
</xsl:template>
<xsl:template match="Page">
<Page>
<Line>
<xsl:for-each select="Item">
<xsl:if test="@Id='1'">
<Tag1><xsl:value-of select="@Value"/></Tag1>
</xsl:if>
<xsl:if test="@Id='2'">
<Tag2><xsl:value-of select="@Value"/></Tag2>
</xsl:if>
<xsl:if test="@Id='3'">
<Tag3><xsl:value-of select="@Value"/></Tag3>
</xsl:if>
</xsl:for-each>
</Line>
</Page>
</xsl:template>
</xsl:stylesheet>
Which only produces:
<Doc>
<Page>
<Line>
<Tag1>A</Tag1>
<Tag2>B</Tag2>
<Tag3>C</Tag3>
<Tag1>D</Tag1>
<Tag2>E</Tag2>
<Tag3>F</Tag3>
<Tag1>G</Tag1>
<Tag2>H</Tag2>
<Tag3>I</Tag3>
</Line>
</Page>
</Doc>
Any help at all is warmly welcomed!