例如,我有一个像xml一样的
<books>
<book id="1">
<title id="11" name="Basic XML"/>
<price id="12" amount="500"/>
<quantity id="13" number="10"/>
</book>
</books>
Run Code Online (Sandbox Code Playgroud)
可以将"Basic XML"一书的名称更新为"Basic XSLT",还是使用XSLT更改任何节点的任何其他属性?如果是的话,有人能给我一些如何做的例子吗?
提前致谢.
这种转变:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:my="my:my">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<my:reps>
<repAttr name="name" value="Basic XSLT"/>
<repAttr name="amount" value="300"/>
<repAttr name="number" value="20"/>
</my:reps>
<xsl:strip-space elements="*"/>
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match=
"@*[name()=document('')/*/my:reps/*/@name]">
<xsl:attribute name="{name()}">
<xsl:value-of select=
"document('')/*/my:reps/*[@name=name(current())]/@value"/>
</xsl:attribute>
</xsl:template>
</xsl:stylesheet>
Run Code Online (Sandbox Code Playgroud)
当应用于提供的XML文档时:
<books>
<book id="1">
<title id="11" name="Basic XML"/>
<price id="12" amount="500"/>
<quantity id="13" number="10"/>
</book>
</books>
Run Code Online (Sandbox Code Playgroud)
产生想要的,正确的结果:
<books>
<book id="1">
<title id="11" name="Basic XSLT"/>
<price id="12" amount="300"/>
<quantity id="13" number="20"/>
</book>
</books>
Run Code Online (Sandbox Code Playgroud)
说明:
身份规则/模板"按原样"复制每个节点.
标识模板由匹配任何属性的单个模板覆盖,该模板的名称可以作为元素中指定的元素的name属性之一的值(XSLT样式表中嵌入的参数)找到.repAttrmy:reps
在这种情况下,将重新创建(不复制)具有相同名称和相应repAttr元素(其value属性)中指定的新值的属性.
| 归档时间: |
|
| 查看次数: |
14481 次 |
| 最近记录: |