[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Access the same level node with different prefix

Subject: Re: Access the same level node with different prefix Index
From: Senthilkumaravelan Krishnanatham <senthil@xxxxxxxxx>
Date: Tue, 20 Feb 2007 12:05:42 -0800
Re:  Access the same level node with different prefix
Hi
Thanks for correcting me the XML and
I need to get each product node I need to get the respective serial number in the parenthesis.
text() might differs so we can that that as criteria of substring and I am wondering ,How I could pass the same node value in the substring argument.
Please advise
Regards,
Senthil


On Feb 20, 2007, at 11:25 AM, Spencer Tickner wrote:

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

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.