Subject: Re: [xsl] Access the same level node with different prefix Index From: Senthilkumaravelan Krishnanatham <senthil@xxxxxxxxx> Date: Tue, 20 Feb 2007 12:05:42 -0800 |
Hello,
Your XML is invalid.. So I had to make a few assumptions.. Mainly that the match is based on the elements name,, not the text() within the element. I rattled it off quickly so I'm sure there is a nicer solution out there.
Anyway, if your XML is indeed suppose to be:
<?xml version="1.0"?> <record> <product1>Item1</product1> <product2>Item2</product2> <product3>Item3</product3> <serial1>serial 1</serial1> <serial2>serial 2</serial2> <serial3>serial 3</serial3> </record>
Then:
<?xml version='1.0'?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/ Transform">
<xsl:template match="record"> <xsl:apply-templates select="*[contains(name(), 'product')]"/> </xsl:template>
<xsl:template match="*[contains(name(), 'product')]"> <xsl:variable name="serialNum" select="concat('serial', substring-after(., 'Item'))"/> <xsl:value-of select="."/><xsl:apply-templates select="following-sibling::*[contains(name(), $serialNum)]"/> </xsl:template>
<xsl:template match="*[contains(name(), 'serial')]">(<xsl:value-of select="."/>)<xsl:text> </xsl:text></xsl:template>
</xsl:stylesheet>
Will produce:
Item1(serial 1) Item2(serial 2) Item3(serial 3)
However, if the relationship is based on text() then you'll have to replace name() with text() and 'product' with 'Item' and tweek at match.
Cheers,
Spencer Tickner
On 2/20/07, Senthilkumaravelan K <skumaravelan@xxxxxxxxxxxxxx> wrote:Hi All, I have structure as <record> <product1>Item1</product1> <product2>Item2</product2> <product3>Item2</product2> ...... ...... <serial1>serial 1</serial1> <serial2>serial 2</serial2> <serial3>serial 3</serial1> ..... ......
</record> and I would get an an output as Item1(serial 1) Item2(serial 2) Item3(serial 3) ... I am not sure How I could do the substring and access the value of other node and form the output as mentioned.
Please help me .
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Access the same level nod, Spencer Tickner | Thread | [xsl] Using xsl:sort to sort negati, Sola Awe |
Re: [xsl] Access the same level nod, Spencer Tickner | Date | [xsl] Using xsl:sort to sort negati, Sola Awe |
Month |