Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>If you refer to the usage of <code>../..</code> in your XPath it's nothing wrong with that in my opinion.</p> <p>But if you use the <code>product/title</code> in many sub templates to the <code>product</code> template, one way to solve it would be to use a tunneled parameter:</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"&gt; &lt;xsl:template match="product"&gt; &lt;!-- Do some other stuff here maybe... --&gt; &lt;xsl:apply-templates&gt; &lt;xsl:with-param name="title" select="title" tunnel="yes"/&gt; &lt;/xsl:apply-templates&gt; &lt;/xsl:template&gt; &lt;xsl:template match="tags"&gt; &lt;!-- ... and some more stuff ... --&gt; &lt;xsl:apply-templates/&gt; &lt;/xsl:template&gt; &lt;xsl:template match="ProductType"&gt; &lt;xsl:param name="title" tunnel="yes"/&gt; &lt;xsl:value-of select="$title"/&gt; &lt;/xsl:template&gt; &lt;/xsl:stylesheet&gt; </code></pre> <p>By using a tunneled parameter you will be able to pick it up in any of the templates for any child node to product. But the nice part is that you don't have to manually send it through all the templates don't need the title in.</p> <p>Here's some more on tunneling parameters: <a href="http://www.xml.com/lpt/a/1386" rel="nofollow noreferrer">http://www.xml.com/lpt/a/1386</a></p> <p>However, this technique requires XSLT 2.0, but you could do the same in XSLT 1.0 but with the caveat that you need to pass the parameter through every template you're processing.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload