Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
| Search | Today's Posts | Mark Forums Read
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 September 1st, 2004, 03:52 PM
Registered User
 
Join Date: Sep 2004
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default XSLT/XPATH Help

I apologize for the vague subject line but I don't know how to sum this up in a few words.

I am transforming an XML file. I have elements that have the same name and same attribute value. What distinguishes them is a text value of a subelement. In this application there are 5 possible iterations of this element. The problem is that the element I need has 4 different qualifying values. Only 1 will be present though, a subtype if you will. None of the 5 elements are required, some may be present, none may be present, and they can be in any order. If there was only 1 qualifying value it is very simple to get the element. But I don't even know how to approach getting it if there are 4 possible text node values to qualify it as this type. The subtype is not important. I don't care what value of the possible 4 it is. I just need the element (if there is one) that has one of those 4 values and process it.

If this makes no sense let me know.

Here's an example. Say I need to get the third element. How do I get it based on the qualifier value? Remember I can't just say get the third one. All are optional and can be in any order.

Code:
<element1 id="10A">
   <qualifier>DN</qualifier>
   ....
</element1>
<element1 id="10A">
   <qualifier>82</qualifier>
   ....
</element1>
<element1 id="10A">
   <qualifier>FA</qualifier> (But could also be TL, 77, or LI)   
   ....
</element1>
Thanks,
Karl
 
Old September 1st, 2004, 04:13 PM
Registered User
 
Join Date: Sep 2004
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I thought of one possible solution. I think I could create a node-list of the elements and do a for-each. Then in the for-each do an if. Maybe something like this:

Code:
<xsl:for-each select="element1[@id='10A']">
   <xsl:variable name="val">
      <xsl:value-of select="qualifier"/>
   </xsl:variable>
   <xsl:if test="$val='77' or $val='FA' or $val='TL' or $val='LI'">
      
   </xsl:if>
</xsl:for-each>
Is there an easier way?

Thanks,
Karl
 
Old September 2nd, 2004, 03:07 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , United Kingdom.
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post
Default

Can't you just use
element1[@id='10A' and (qualifier='FA' or qualifier='TL' or qualifier='77' or qualifier='LI')]
 
Old September 2nd, 2004, 07:35 AM
Registered User
 
Join Date: Sep 2004
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Yes, that worked. Thanks a lot.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Array like processing (Xpath 1 / XSLT 1) akentanaka XSLT 1 July 2nd, 2008 02:22 AM
JAXP and XSLT 2.0 / XPATH 2.0 ojasrege XSLT 2 November 27th, 2007 10:40 AM
xslt xpath boris17 XSLT 2 October 15th, 2007 05:31 PM
XPath & XSLT problem Andy-7M XSLT 7 May 3rd, 2007 02:50 AM
XSLT -XPATH Error xslspy XSLT 1 October 27th, 2005 03:24 AM





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