 |
| 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
|
|
|
|

August 3rd, 2011, 03:21 PM
|
|
Authorized User
|
|
Join Date: Jul 2010
Posts: 74
Thanks: 23
Thanked 0 Times in 0 Posts
|
|
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..
|
|

August 3rd, 2011, 05:32 PM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
|
|
If you want to select a specific node then use something like this:
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>
|
|
The Following User Says Thank You to samjudson For This Useful Post:
|
|
|

August 3rd, 2011, 05:37 PM
|
|
Authorized User
|
|
Join Date: Jul 2010
Posts: 74
Thanks: 23
Thanked 0 Times in 0 Posts
|
|
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..
|
|

August 4th, 2011, 12:05 PM
|
|
Authorized User
|
|
Join Date: Jul 2010
Posts: 74
Thanks: 23
Thanked 0 Times in 0 Posts
|
|
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!
|
|

August 4th, 2011, 12:43 PM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
|
|
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.
|
|

August 4th, 2011, 12:44 PM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
|
|
Oh, and I use Kernow for Saxon to test my XSLT.
http://kernowforsaxon.sourceforge.net/
|
|

August 4th, 2011, 01:35 PM
|
|
Authorized User
|
|
Join Date: Jul 2010
Posts: 74
Thanks: 23
Thanked 0 Times in 0 Posts
|
|
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?
|
|

August 4th, 2011, 02:09 PM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
|
|
The 1 means the first one (i.e. the first sibling that is a 'parameter' element).
|
|
The Following User Says Thank You to samjudson For This Useful Post:
|
|
|

August 4th, 2011, 02:25 PM
|
|
Authorized User
|
|
Join Date: Jul 2010
Posts: 74
Thanks: 23
Thanked 0 Times in 0 Posts
|
|
Thank you, Sam.
And the tool is really really great!
|
|
 |