xslt 2.0 - Separating data into groups -
i think i'm missing simple here. have source xml file
<inventory division="b" xmlns:xsl="http://www.w3.org/1999/xsl/transform"> <stackgroup name="warehouse"> <stack> <mainstack name="primary"> <mainstackgroup name="group_primary"> <mainstacklayer sequence="1"> <stacklayerref id="layer_1"/> </mainstacklayer> </mainstackgroup> </mainstack> <mainstack name="secondary"> <mainstackgroup name="group_secondary"> <mainstacklayer sequence="2"> <stacklayerref id="layer_2"/> </mainstacklayer> </mainstackgroup> </mainstack> </stack> </stackgroup> </inventory>
i'm applying stylesheet:
<?xml version="1.0" encoding="iso-8859-1"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/xsl/transform" version="2.0"> <xsl:output method="xml" indent="yes"/> <xsl:template match="/"> <mainstack> <numberofstacks> <xsl:value-of select="count(/inventory/stackgroup/stack/mainstack)"/> </numberofstacks> <stackdisplayorder> <xsl:apply-templates select="/inventory/stackgroup/stack/mainstack" mode="order"/> </stackdisplayorder> <xsl:apply-templates select="/inventory/stackgroup/stack/mainstack" mode="stacklist"/> </mainstack> </xsl:template> <xsl:template match="/inventory/stackgroup/stack/mainstack" mode="order"> <index><xsl:value-of select="position() - 1" /></index> </xsl:template> <xsl:template match="/inventory/stackgroup/stack/mainstack" mode="stacklist"> <stack> <index><xsl:value-of select="position() - 1" /></index> <name> <xsl:value-of select="/inventory/stackgroup/stack/mainstack/@name"/> </name> <groupname> <xsl:value-of select="/inventory/stackgroup/stack/mainstack/mainstackgroup/@name"/> </groupname> <sequenceno> <xsl:value-of select="/inventory/stackgroup/stack/mainstack/mainstackgroup/mainstacklayer/@sequence"/> </sequenceno> <layerno> <xsl:value-of select="/inventory/stackgroup/stack/mainstack/mainstackgroup/mainstacklayer/stacklayerref/@id"/> </layerno> </stack> </xsl:template> </xsl:stylesheet>
i following output:
<?xml version="1.0" encoding="utf-8"?> <mainstack> <numberofstacks>2</numberofstacks> <stackdisplayorder> <index>0</i`enter code here`ndex> <index>1</index> </stackdisplayorder> <stack> <index>0</index> <name>primary secondary</name> <groupname>group_primary group_secondary</groupname> <sequenceno>1 2</sequenceno> <layerno>layer_1 layer_2</layerno> </stack> <stack> <index>1</index> <name>primary secondary</name> <groupname>group_primary group_secondary</groupname> <sequenceno>1 2</sequenceno> <layerno>layer_1 layer_2</layerno> </stack> </mainstack>
the template finds 2 matches , concatenates data both. how can separate them?
thanks in advance!
use relative paths change e.g.
<name> <xsl:value-of select="/inventory/stackgroup/stack/mainstack/@name"/> </name>
to
<name> <xsl:value-of select="@name"/> </name>
and on paths in template.
Comments
Post a Comment