.net - Apply ALL templates -


my main xslt file imports multiple other xslt files, , xslt files may import/include 0, 1 or many xslt files (and more levels possible too)

i'd way to, main xslt file, call imported/included templates match specific pattern (either have same name, same mode, same matches, or else).

i'd able without hard-coding specific list of imports (i.e. if add new import should picked automatically)

alternatively, extract value of variable given name.

in either case results should concatenated single nodeset. order of results not important , wrapper element optional (but desirable)

is possible?

example inputs:

main.xslt

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/xsl/transform">   <xsl:import href="file1.xslt"/>   <!-- rules here, including solution --> </xsl:style> 

file1.xslt

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/xsl/transform">   <xsl:import href="file2.xslt"/>   <!-- unrelated rules here -->   <xsl:template name="things">     <!-- name mode or matches, or template variable instead -->     <something/>   </xsl:template> </xsl:style> 

file2.xslt

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/xsl/transform">   <!-- unrelated rules here -->   <xsl:template name="things">     <!-- name mode or matches, or template variable instead -->     <somethingelse/>   </xsl:template> </xsl:style> 

required output:

<xml>   <something/>   <somethingelse/> </xml> 

n.b. in scenario content of required templates/variables static, although nice have solution contain xslt.

i've come hacky way this.

<xsl:template name="entrypoint">   <xml>     <xsl:apply-templates select="document('')/xsl:stylesheet/xsl:import/@href" mode="findthings"/>   </xml> </xsl:template> <xsl:template mode="findthings" match="/xsl:stylesheet">   <xsl:apply-templates select="document(xsl:import/@href)" mode="findthings"/>   <xsl:apply-templates select="xsl:variable[@name='things']" mode="findthings"/> </xsl:template> <xsl:template mode="findthings" match="xsl:variable[@name='things']">   <xsl:copy-of select="*"/> </xsl:template> <xsl:template mode="findthings" match="xsl:import/@href">   <xsl:apply-templates select="document(.)" mode="findthings"/> </xsl:template> 

it outputs contents of top-level variables called "things" within every imported xslt file, no matter depth of import.


Comments

Popular posts from this blog

python Tkinter Capturing keyboard events save as one single string -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

javascript - Z-index in d3.js -