exslt - Best approach for combining several XSLT 1.0 passes which process the same nodes -
i'm doing complex xslt 1.0 transformation (currently using 8 xslt passes). want combine 8 passes without merging them in 1 file (this complex). solution using xsl:include
, exsl:node-set
merge passes , store temporary results in variables.
but have 1 problem: transformation passes copies of nodes , modifying aspects. therefore need process same nodes in every pass, different xsl:template
! how do that? how tell after first pass want apply templates other xslt stylesheet?
very simplified example i'm doing (2 xslt passes):
source:
<h>something here</h>
after xslt pass 1:
<h someattribute="1">something here</h>
after xslt pass 2:
<h someattribute="1" somemoreattribute="2">something here, , more</h>
my current approach call xslt processor twice , saving results temporary on disk:
xsltproc stylesheet1.xsl input.xml >temp.xml xsltproc stylesheet2.xsl temp.xml >finalresult.xml
one possible solution change each of stylesheets use distinct mode. import them master stylesheet , multiple passes applying templates using each mode in turn:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/xsl/transform" xmlns:exsl="http://exslt.org/common" extension-element-prefixes="exsl" version="1.0"> <xsl:import href="stylesheet1.xsl"/> <!-- assuming mode="stylesheet1" --> <xsl:import href="stylesheet2.xsl"/> <!-- assuming mode="stylesheet2" --> <xsl:import href="stylesheet3.xsl"/> <!-- assuming mode="stylesheet3" --> <xsl:template match="/"> <xsl:variable name="temp1"> <xsl:apply-templates select="." mode="stylesheet1"/> </xsl:variable> <xsl:variable name="temp2"> <xsl:apply-templates mode="stylesheet2" select="exsl:node-set($temp1)"/> </xsl:variable> <xsl:apply-templates mode="stylesheet3" select="exsl:node-set($temp2)"/> </xsl:template> </xsl:stylesheet>
the downside need modify original stylesheets, adding appropriate mode
attributes each xsl:template
and xsl:apply-templates
. can still make stylesheets work independently adding template in each of them:
<xsl:template match="/"> <xsl:apply-templates select="." mode="stylesheet1"/> </xsl:template>
Comments
Post a Comment