Passing Xpath in XSLT
I am trying to insert xml elements into an xml file using XSLT. I have two files, input file that contains the xpaths (ex: /root/element ) and depending on the input xpath I insert the element into the output file, for example if the input element value is /root/element then I should insert new_element into that destination so the output will be
<root>
<new_element id="1">some content</new_element>
<ele开发者_开发知识库ment>some content</element>
</root>
I am populating a variable with the xpath input and then using the variable, but I am getting an error message "parameters and variables can not be used in patterns). Here is the part where I am using the variable:
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
I am very new to XSLT so I am not sure what I am doing wrong, or if my logic to do is not appropriate.
I will appreciate your help :)
Thanks
In XSLT 1.0, variables cannot be used in match patterns. Match patterns are the expressions you suplly to an <xsl:template match="...">
. You have to use literals in those cases. Consider that the templates are compiled before they are executed, so having a variable in the compiled expression could make it perform less well.
If you're new to XSLT and have an interest in learning it, there are a couple good resources on the net (start with Jeni Tennison's website, as well as in printed form.
精彩评论