wrote:
> <A>
> <B>
> <C>111</C>
> <C>222</C>
> <C>333</C>
> </B>
> <B>
> <C>444</C>
> <C>555</C>
> <C>666</C>
> </B>
> </A>
>
> The number of A is known but not the number of B. The number of B is
> equal in each A.
> The xml format is fixed and can't be changed.
>
> I'd like to have the following result
>
> 1 111-444
> 2 222-555
> 3 333-666
I am not sure why you could have several A elements (as A in your
example is the root element and there can be only one root element) but
the following stylesheet is one way to get the output
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
xmlns

sl="http://www.w3.org/1999/XSL/Transform">
<xsl

utput method="text"/>
<xsl:template match="A">
<xsl:apply-templates select="B[1]" />
</xsl:template>
<xsl:template match="B">
<xsl:apply-templates select="C" />
</xsl:template>
<xsl:template match="C">
<xsl:variable name="currentPos" select="position()" />
<xsl:value-of select="$currentPos" />
<xsl:text> </xsl:text>
<xsl:value-of select="." />
<xsl:apply-templates
select="../following-sibling::B/C[$currentPos]" mode="lineUp" />
<xsl:text>
</xsl:text>
</xsl:template>
<xsl:template match="C" mode="lineUp">
<xsl:text>-</xsl:text>
<xsl:value-of select="." />
</xsl:template>
</xsl:stylesheet>
even if there are more B elements as long as the C elements match.
--
Martin Honnen
http://JavaScript.FAQTs.com/