David Parks
David Parks

Reputation: 32081

XSLT/XPath quoting: XPath within an XPath-Function within XSLT

Here we're using double quotes at the XSLT level; single quotes at the XPath function level, but when we need to embed an XPath expression within the XPath function, how do we quote that?

 <xsl:value-of select="document('price-list.xml','/im_prices/row/UPC_Code[text()='abc']"/>
                                                                                 ^^^^^

(scroll to the right)

Upvotes: 0

Views: 172

Answers (2)

Michael Kay
Michael Kay

Reputation: 163458

The second argument of document() is a node-set, not a string, so the problem should not arise. However, there are of course other cases where it can arise.

In XSLT 2.0:

  • if you want to include the attribute delimiter in a string, escape it as &quot; or &apos;

  • if you want to include the string delimiter in a string, double it as '' or "".

In XSLT 1.0, the second option is not available. You can get around it either

(a) by swapping the character used for the attribute delimiter and the string delimiter

(b) by using concat() to build the string

Upvotes: 0

Woody
Woody

Reputation: 5130

Not sure about that, I have always used the node-set form of:

<xsl:value-of select="document('price-list.xml')/im_prices/row/UPC_Code[text()='abc']"/>

but that may be vendor specific (however, have never known it not to work!)

Upvotes: 1

Related Questions