What are the hidden features of XPath AND XSLT?
+2
A:
A dirty little hack, to start things off:
Conditional strings in Xpath by abusing the fact that true is 1 and false is 0.
Example:
<div class="ID{substring('-on', 4-4*($Var = 2))}">
Yields <div class="ID-on">
or <div class="ID">
, depending on if $Var
is 2.
Brian
2009-10-05 19:15:32
This is called "Becker's method".
jelovirt
2009-12-08 14:09:56
+5
A:
document('')
Accessing the XSLT document itself with document('')
. Occasionally useful for stuff like accessing lookup tables stored inside the stylesheet itself, eliminating the need for an external file.
Jukka Matilainen
2009-10-05 21:35:07
I'm not sure I'd really consider that a "hidden" feature, given that it is clearly stated in the spec: *'document("") refers to the root node of the stylesheet; the tree representation of the stylesheet is exactly the same as if the XML document containing the stylesheet was the initial source document'* - http://www.w3.org/TR/xslt#document Still, a surprising number of people don't know it, so +1 anyway :-)
NickFitz
2009-10-06 11:11:42