Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 3rd, 2011, 03:21 PM
Authorized User
 
Join Date: Jul 2010
Posts: 74
Thanks: 23
Thanked 0 Times in 0 Posts
Question How to choose different nodes in the same name with different attributes

input xml:
<response>
--<para pos="0">
----<aaa>Hi, there.</aaa>
------<aaaA>Nested,lol</aaaA>
--<para pos="1"/>
--<para pos="2">646464</para>
--<para>123456</para>
--<para pos="3"/>
--<para pos="4"/>
--<para pos="5">0</para>
--<para>WHAT IS THIS?</para>
--<para pos="6"/>
--<para pos="7">N</para>
--<para>
----<presc>45864</presc>
----<pred>Help!</pred>
--</para>

--<para pos="8"/>
--<para pos="9"/>
--<para pos="10"/>
--<para pos="11"/>

the output xml:
<AV>
--<Address attr1="Hi, there." pa="Nested,lol" fc="123456" nf="WHAT IS THIS?"/>

I need the xsl to:
1. How to choose different node with the same name, but different attribute?

2. How to deal with the node in the red color? These are following the previous line, just with the same node name. Like the father and child have the same name.

I do not know whether I explain the question clear.

Thank you in advance for help.

Last edited by JohnKiller; August 4th, 2011 at 02:03 PM..
 
Old August 3rd, 2011, 05:32 PM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

If you want to select a specific node then use something like this:

Code:
para[@pos='2']
If you want the next para element after this one then use something like this:

Code:
para[@pos='2']/following-sibling::para[1]
So the complete template might look like this:

Code:
<xsl:template match="response">
<AV>
  <Address attr1="{para[@pos='0']/aaa}" pa="{para[@pos='0']/aaaA}" fc="{para[@pos='2']/following-sibling::para[1]}" nf={para[@pos='5']/following-sibling::para[1]}"/>
</AV>
</xsl:template>
__________________
/- Sam Judson : Wrox Technical Editor -/

Think before you post: What have you tried?
The Following User Says Thank You to samjudson For This Useful Post:
JohnKiller (August 3rd, 2011)
 
Old August 3rd, 2011, 05:37 PM
Authorized User
 
Join Date: Jul 2010
Posts: 74
Thanks: 23
Thanked 0 Times in 0 Posts
Default

I changed the output a little bit,

<AV>
--<Address attr1="Hi, there." pa="Nested,lol" fc="123456" nf="WHAT IS THIS?" ab="45864" bc="Help!"/>

And I do not know how to output the "Help!"

Thank you, Sam!

Last edited by JohnKiller; August 4th, 2011 at 12:04 PM..
 
Old August 4th, 2011, 12:05 PM
Authorized User
 
Join Date: Jul 2010
Posts: 74
Thanks: 23
Thanked 0 Times in 0 Posts
Default

I changed the output a little bit,

<AV>
--<Address attr1="Hi, there." pa="Nested,lol" fc="123456" nf="WHAT IS THIS?" ab="45864" bc="Help!"/>
</AV>

And I do not know how to output the "Help!"

By the way, what kind of tools or program you used to test these xsl?

Thank you, Sam!
 
Old August 4th, 2011, 12:43 PM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

well if there is only one <para> that has a <pred> element then bc="{para/pred}" would work. Otherwise just add "/pred" onto the end of an xpath similar to one you already have to select the child <pref> element.
__________________
/- Sam Judson : Wrox Technical Editor -/

Think before you post: What have you tried?
 
Old August 4th, 2011, 12:44 PM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

Oh, and I use Kernow for Saxon to test my XSLT.

http://kernowforsaxon.sourceforge.net/
__________________
/- Sam Judson : Wrox Technical Editor -/

Think before you post: What have you tried?
 
Old August 4th, 2011, 01:35 PM
Authorized User
 
Join Date: Jul 2010
Posts: 74
Thanks: 23
Thanked 0 Times in 0 Posts
Default

Thank you so much, Sam. I am confusing about parameter[1] in the
/following-sibling::parameter[1]
What does the [1] mean? Can it be changed to [2] or [0] in some situations?
 
Old August 4th, 2011, 02:09 PM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

The 1 means the first one (i.e. the first sibling that is a 'parameter' element).
__________________
/- Sam Judson : Wrox Technical Editor -/

Think before you post: What have you tried?
The Following User Says Thank You to samjudson For This Useful Post:
JohnKiller (August 4th, 2011)
 
Old August 4th, 2011, 02:25 PM
Authorized User
 
Join Date: Jul 2010
Posts: 74
Thanks: 23
Thanked 0 Times in 0 Posts
Default

Thank you, Sam.

And the tool is really really great!





Similar Threads
Thread Thread Starter Forum Replies Last Post
Unique nodes based on two attributes malim_sheikh XSLT 2 August 11th, 2009 07:38 AM
How to select attributes in previous nodes JoshC XSLT 2 March 8th, 2009 05:40 PM
selecting nodes that lack certain attributes rmers XSLT 3 October 4th, 2006 03:44 PM
XML DOM :modifying the existing nodes attributes i sharmasourabh54 XML 1 February 14th, 2005 05:04 AM
Need to copy all nodes, attributes, and namespaces juaniux XSLT 4 October 22nd, 2004 04:39 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.