假设我有一个大型XML文件,其结构如下:
<MyXml>
<Data1>
<Node1>1234</Node1>
<Node2>abc<Node2>
<Node3>gfdf</Node3>
...
<Node10000>more text</Node10000>
</Data1>
<Data2>
...
</Data2>
</MyXml>
Run Code Online (Sandbox Code Playgroud)
我希望将这个XML转换为另一个看起来完全相同的XML,但是将某个字符串连接到某个节点,比如Node766.我当然正在使用XSLT,并想知道除了Node766之外我怎么能告诉它除了Node766之外还要复制每个东西,在输出之前我必须做些什么.
Mad*_*sen 66
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<!--Identity template,
provides default behavior that copies all content into the output -->
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<!--More specific template for Node766 that provides custom behavior -->
<xsl:template match="Node766">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
<!--Do something special for Node766, like add a certain string-->
<xsl:text> add some text </xsl:text>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
64420 次 |
| 最近记录: |