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

May 10th, 2005, 03:52 PM
|
|
Registered User
|
|
Join Date: Apr 2005
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
how to read delimiters
How do I get only those elements (<B val="3"/> and <B val ="1"/> in this case) for which the value of val is contained in the req attribute in condition element.
<?xml version="1.0"?>
<A>
<condition req="3|1"/>
<B val="1"></B>
<B val="2"></B>
<B val="3"></B>
...
...
</A>
Thanks!
|
|

May 10th, 2005, 04:41 PM
|
 |
Wrox Author
|
|
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
|
|
/A/B[contains(../condition/@req, @val)]
Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
|
|

May 10th, 2005, 04:45 PM
|
|
Registered User
|
|
Join Date: Apr 2005
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
But,
for <condition req="13"/> ,if
<B val="1"></B>
<B val="2"></B>
<B val="3"></B>
..
..
<B val="13"></B>,
how do I prevent <B val="1"></B> and <B val="3"></B> from appearing in my output.
|
|

May 10th, 2005, 05:58 PM
|
 |
Wrox Author
|
|
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
|
|
I thought you might follow up with that. If the list is always separated with vertical bar and there are no spaces anywhere you could try
/A/B[contains(
concat('|', ../condition/@req, '|'),
concat('|', @val, '|')]
In XSLT 2.0 you can do
/A/B[@val = tokenize(../condition/@req, '|')]
Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
|
|

May 11th, 2005, 09:06 AM
|
|
Registered User
|
|
Join Date: Apr 2005
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
The concat fn did work.
How do I determine the output sequence (depending on the sequence of numbers appearing in req attribute )such that for the following xml
<A>
<condition req="3|1|2"/>
<B val="1"></B>
<B val="2"></B>
<B val="3"></B>
...
...
</A>
the output order should be
<B val="3"></B> ,<B val="1"></B> and <B val="2"></B>
Thanks in advance!
|
|

May 11th, 2005, 09:37 AM
|
 |
Wrox Author
|
|
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
|
|
For that I think you really do need tokenize:
In XSLT 2.0:
<xsl:copy-of select="for $t in tokenize(condition/@req, '|')
return B[@val=$t]"/>
You can find a version of tokenize that works with XSLT 1.0 at www.exslt.org, but of course you'll have to expand the above code using xsl:for-each and variables.
Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
|
|

May 11th, 2005, 11:00 AM
|
|
Registered User
|
|
Join Date: Apr 2005
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I am using xslt 1.0
Could you help me to figure out a way of doing it on 1.0
Thanks in advance!
|
|

May 11th, 2005, 11:20 AM
|
 |
Wrox Author
|
|
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
|
|
I find doing these things in 1.0 no fun at all, so I'll leave this to someone else.
Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
|
|
 |