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 May 10th, 2005, 03:52 PM
Registered User
 
Join Date: Apr 2005
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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!
 
Old May 10th, 2005, 04:41 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

/A/B[contains(../condition/@req, @val)]

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old May 10th, 2005, 04:45 PM
Registered User
 
Join Date: Apr 2005
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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.



 
Old May 10th, 2005, 05:58 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

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
 
Old May 11th, 2005, 09:06 AM
Registered User
 
Join Date: Apr 2005
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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!

 
Old May 11th, 2005, 09:37 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

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
 
Old May 11th, 2005, 11:00 AM
Registered User
 
Join Date: Apr 2005
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I am using xslt 1.0
Could you help me to figure out a way of doing it on 1.0

Thanks in advance!

 
Old May 11th, 2005, 11:20 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

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





Similar Threads
Thread Thread Starter Forum Replies Last Post
using delimiters---i need Heeeeelp!!! ssimkhan Pro Java 1 June 15th, 2007 06:55 AM
using delimiters---i need Heeeeelp!!! ssimkhan Java Basics 1 June 15th, 2007 06:22 AM
Read Only Form Is not Read only lryckman Access VBA 3 June 12th, 2007 06:30 AM
Read First!! I need you o help :-) Stephen Lam MySQL 1 April 15th, 2005 10:12 AM
Export Delimiters CodingMonkey VB Databases Basics 0 August 19th, 2004 12:40 PM





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