Using dynamic xpath in XSLT

前端 未结 3 1202
感动是毒
感动是毒 2020-12-21 22:42

I am using a variable say xpathvar in the XSLT whose value will be supplied at the time of call to XSLT. How can i achieve this? My XSLT file looks like -

&         


        
相关标签:
3条回答
  • 2020-12-21 23:32

    If I mention the variable in the for-each, it throws error

    In XSLT 1.0 (it looks you are using Xalan), you can iterate over node sets, only. So $xpathvar should be an instance of node set data type.

    In XSLT 2.0 you can iterate over sequence (including scalar values).

    Also, if the string containing the "dynamic" XPath expression is simple enough (only QName test step, maybe positional predicates) this could be done (as is already answered in SO) with standar XSLT.

    0 讨论(0)
  • 2020-12-21 23:33

    I dont think this can be done like this you must use xpath so example would be

    <template match="Node[name=$xpathvar]" />
    
    
    <xsl:for-each select="*[name()=$xpathvar]">
    </xsl:for-each>
    

    I think it does not let you use the variable directly because it is not a nodeset.

    0 讨论(0)
  • 2020-12-21 23:42

    According to Global xsl:param containing xpath expression string it can't be done purely with plain old XSLT, you need to use the evaluate extension see: Xalan evaluate expression

    0 讨论(0)
提交回复
热议问题