[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Can a single XPath statement duplicate the functional

Subject: Can a single XPath statement duplicate the functionality of this verbose <xsl:choose> statement?
From: "Mark" <mark@xxxxxxxxxxxx>
Date: Sun, 23 Oct 2011 17:10:08 -0700
 Can a single XPath statement  duplicate the functional
Although they do have the virtue of giving me my desired output, can the following sequence of statements be replaced by a more generalized (shorter and simpler) XPath statement without the repetitive "when" tests shown below?

<xsl:choose>
<xsl:when test="@souvenir-sheet">
<xsl:copy-of select="if (../Location/@souvenir-sheet) then ../Location/@souvenir-sheet else if (../Location/@denomination) then ../Location/@denomination else '0' "/>
</xsl:when>
<xsl:when test="@minisheet">
<xsl:copy-of select="if(../Location/@minisheet) then ../Location/@minisheet else if(../Location/@denomination) then ../Location/@denomination else '0'"/>
</xsl:when>
<xsl:when test="@booklet">
<xsl:copy-of select="if(../Location/@booklet) then ../Location/@booklet else if(../Location/@denomination) then ../Location/@denomination else '0'"/>
</xsl:when>
<xsl:when test="@se-tenant">
<xsl:copy-of select="if (../Location/@se-tenant) then ../Location/@se-tenant else if(../Location/@denomination) then ../Location/@denomination else '0'"/>
</xsl:when>
<xsl:when test="@coupon">
<xsl:copy-of select=" if (../Location/@coupon) then ../Location/@coupon else if(../Location/@denomination) then ../Location/@denomination else '0'"/>
</xsl:when>
</xsl:choose>


My XPath is very weak.

I tried:
<xsl:copy-of select="if (../Location[name(@*)=name(@*)]) then ../Location/@* else if(../Location/@denomination) then ../Location/@denomination else '0'"></xsl:copy-of>


but it does not restrict the first "then" to returning the value of only locations with an attribute of the same name (as shown in the series of <when> statements).

The current context is a <Formats> element with a single attribute (@minisheet, etc.). <Location> elements, if they exist, have a one-to-one relationship with respect to their attribute with their sibling <Formats> elements, i.e, a <Formats @minisheet> element is paired with exactly one <Location @minisheet> sibling, or with no <Location> element at all. In that case substitute value of the single <Locations @denomination> element if it exists, or provide a value of '0' if it does not.

If there is not enough info here to correct my faulty try at a simpler XPath statement or to tell me its not going to work no matter what, then I can provide a brief input and desired output selection.

Thanks,
Mark

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.