1
votes

I'm using XSLT 1.1 and I have an external document I am accessing like so:

<xsl:variable name="doc2URI" select="ancestor-or-self::book/@secondDoc"/>
<xsl:variable name="doc2" select="document($doc2URI)"/>

What I'm trying to do is apply the template for a node in this document that is obtained by an XPath expression found in an XSLT variable:

<xsl:variable name="xpath">
  <xsl:call-template name="genPath"/>
</xsl:variable>

The $xpath variable for instance, could at one point in the code contain the result of: /book[1]/title[1].

What I'd like to do is:

 <xsl:apply-templates select="$doc2/$xpath"/>

But that doesn't work. If I go:

 <xsl:apply-templates select="$doc2/book[1]/title[1]"/>

That does work, but there's no way I will know the exact XPath expression beforehand. It'll only be available through that $xpath variable.

My question is, how can I apply the template to that external document through the XPath expression contained in the $xpath variable?

1
It's very unlikely you are using XSLT 1.1 - that was a working draft published in 2001 and then abandoned. There were implementations but they either progressed to XSLT 2.0 (like Saxon) or disappeared off the face of the earth (like jd.xslt). - Michael Kay
I think it might be 1.1. This is at the top of my stylesheet <xsl:stylesheet xmlns:xsl="w3.org/1999/XSL/Transform" xmlns:axf="antennahouse.com/names/XSL/Extensions" xmlns:fo="w3.org/1999/XSL/Format" xmlns:saxon="icl.com/saxon" xmlns:lxslt="xml.apache.org/xslt" xmlns:xalanredirect="org.apache.xalan.xslt.extensions.Redirect" xmlns:exsl="exslt.org/common" xmlns:doc="nwalsh.com/xsl/documentation/1.0" version="1.1" exclude-result-prefixes="doc" extension-element-prefixes="saxon xalanredirect lxslt exsl"> - Paul B
You could write version="93.7" at the top of your stylesheet but that wouldn't make it conform to version 93.7 of the XSLT specification. - Michael Kay

1 Answers

0
votes

You are basically looking for eval for XSLT. This is al XSLT 3.0 feature.

In earlier versions you'll need an extension. See:

XSL. Evaluate expression