Xslt 谓词的谓词中的current()是什么
另一个XPath/XSL问题:) 如果我有一个节点树,如: A --B(任意类型=宠物) ----C(类型=鸟) ----C(类型=cat) ----C(类型=狗) --B(工作动物) ----C(类型=奶牛) ----C(类型=大象) -AXslt 谓词的谓词中的current()是什么,xslt,xpath,Xslt,Xpath,另一个XPath/XSL问题:) 如果我有一个节点树,如: A --B(任意类型=宠物) ----C(类型=鸟) ----C(类型=cat) ----C(类型=狗) --B(工作动物) ----C(类型=奶牛) ----C(类型=大象) -A 还有另一个xml文件($xmlFile),它列出了给定anymal类型所需的类型 -宠物 ----猫 ----狗 -工作动物 ----象 如何仅选择$xmlFile命令我选择的动物 在本例中,current()指的是什么: -模板匹配的节点是(“A”
还有另一个xml文件($xmlFile),它列出了给定anymal类型所需的类型 -宠物 ----猫 ----狗 -工作动物 ----象 如何仅选择$xmlFile命令我选择的动物 在本例中,current()指的是什么: -模板匹配的节点是(“A”) -或者它是当前正在求值的C节点 到达当前正在评估的C节点并向上移动一个节点(到定义动物类型的B节点)的正确方法是什么
谢谢。这一转变:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:variable name="vrtfXmlFile">
<pets>
<animal>cat</animal>
<animal>dog</animal>
</pets>
<working-animals>
<animal>elephant</animal>
</working-animals>
</xsl:variable>
<xsl:variable name="vxmlFile" select=
"document('')/*/xsl:variable
[@name='vrtfXmlFile']"/>
<xsl:template match="node()|@*" name="identity">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="b">
<xsl:if test="$vxmlFile/*[name()=current()/@animal-types]">
<xsl:call-template name="identity"/>
</xsl:if>
</xsl:template>
<xsl:template match="c">
<xsl:if test=
"$vxmlFile/*[name()=current()/../@animal-types]
/animal[.=current()/@type]">
<xsl:call-template name="identity"/>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
<a>
<b animal-types="pets">
<c type="bird"/>
<c type="cat"/>
<c type="dog"/>
</b>
<b animal-types="working-animals">
<c type="cow"/>
<c type="elephant"/>
</b>
</a>
<a>
<b animal-types="pets">
<c type="cat"/>
<c type="dog"/>
</b>
<b animal-types="working-animals">
<c type="elephant"/>
</b>
</a>
猫
狗
大象
应用于此XML文档时:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:variable name="vrtfXmlFile">
<pets>
<animal>cat</animal>
<animal>dog</animal>
</pets>
<working-animals>
<animal>elephant</animal>
</working-animals>
</xsl:variable>
<xsl:variable name="vxmlFile" select=
"document('')/*/xsl:variable
[@name='vrtfXmlFile']"/>
<xsl:template match="node()|@*" name="identity">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="b">
<xsl:if test="$vxmlFile/*[name()=current()/@animal-types]">
<xsl:call-template name="identity"/>
</xsl:if>
</xsl:template>
<xsl:template match="c">
<xsl:if test=
"$vxmlFile/*[name()=current()/../@animal-types]
/animal[.=current()/@type]">
<xsl:call-template name="identity"/>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
<a>
<b animal-types="pets">
<c type="bird"/>
<c type="cat"/>
<c type="dog"/>
</b>
<b animal-types="working-animals">
<c type="cow"/>
<c type="elephant"/>
</b>
</a>
<a>
<b animal-types="pets">
<c type="cat"/>
<c type="dog"/>
</b>
<b animal-types="working-animals">
<c type="elephant"/>
</b>
</a>
生成所需的正确结果:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:variable name="vrtfXmlFile">
<pets>
<animal>cat</animal>
<animal>dog</animal>
</pets>
<working-animals>
<animal>elephant</animal>
</working-animals>
</xsl:variable>
<xsl:variable name="vxmlFile" select=
"document('')/*/xsl:variable
[@name='vrtfXmlFile']"/>
<xsl:template match="node()|@*" name="identity">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="b">
<xsl:if test="$vxmlFile/*[name()=current()/@animal-types]">
<xsl:call-template name="identity"/>
</xsl:if>
</xsl:template>
<xsl:template match="c">
<xsl:if test=
"$vxmlFile/*[name()=current()/../@animal-types]
/animal[.=current()/@type]">
<xsl:call-template name="identity"/>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
<a>
<b animal-types="pets">
<c type="bird"/>
<c type="cat"/>
<c type="dog"/>
</b>
<b animal-types="working-animals">
<c type="cow"/>
<c type="elephant"/>
</b>
</a>
<a>
<b animal-types="pets">
<c type="cat"/>
<c type="dog"/>
</b>
<b animal-types="working-animals">
<c type="elephant"/>
</b>
</a>
注释:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:variable name="vrtfXmlFile">
<pets>
<animal>cat</animal>
<animal>dog</animal>
</pets>
<working-animals>
<animal>elephant</animal>
</working-animals>
</xsl:variable>
<xsl:variable name="vxmlFile" select=
"document('')/*/xsl:variable
[@name='vrtfXmlFile']"/>
<xsl:template match="node()|@*" name="identity">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="b">
<xsl:if test="$vxmlFile/*[name()=current()/@animal-types]">
<xsl:call-template name="identity"/>
</xsl:if>
</xsl:template>
<xsl:template match="c">
<xsl:if test=
"$vxmlFile/*[name()=current()/../@animal-types]
/animal[.=current()/@type]">
<xsl:call-template name="identity"/>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
<a>
<b animal-types="pets">
<c type="bird"/>
<c type="cat"/>
<c type="dog"/>
</b>
<b animal-types="working-animals">
<c type="cow"/>
<c type="elephant"/>
</b>
</a>
<a>
<b animal-types="pets">
<c type="cat"/>
<c type="dog"/>
</b>
<b animal-types="working-animals">
<c type="elephant"/>
</b>
</a>
document(someuri)
函数来读取、解析并将其定义为$vxmlFile
变量的内容