[英]Replacing all matching nodes in XML using XSLT
I wanted to replace all matching nodes in the xml-file. 我想替换xml文件中的所有匹配节点。
To the original xml: 到原始xml:
<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<StackPanel>
<Button/>
</StackPanel>
</Window>
I applied the following xslt: 我应用了以下xslt:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()" />
</xsl:copy>
</xsl:template>
<xsl:template match="Button">
<AnotherButton><xsl:apply-templates select="@*|node()" /></AnotherButton>
</xsl:template>
</xsl:stylesheet>
But it produces the same xml. 但是它产生相同的xml。 What I did wrong?
我做错了什么?
What Sean is saying is that if you remove the namespace from your XML document the XSLT will work Sean的意思是,如果您从XML文档中删除名称空间,那么XSLT将可以正常工作
<Window>
<StackPanel>
<Button/>
</StackPanel>
</Window>
produces... 生产...
<Window>
<StackPanel>
<AnotherButton />
</StackPanel>
</Window>
Alternatively , you asked if you can keep your namespace 或者 ,您询问是否可以保留名称空间
Add your x:
namespace to your Button... 将
x:
命名空间添加到Button中...
<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<StackPanel>
<x:Button/>
</StackPanel>
</Window>
Update your XSL to also use this x:Button
namespace 更新您的XSL以也使用此
x:Button
命名空间
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()" />
</xsl:copy>
</xsl:template>
<xsl:template match="x:Button">
<x:AnotherButton><xsl:apply-templates select="@*|node()" /></x:AnotherButton>
</xsl:template>
</xsl:stylesheet>
produces... 生产...
<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<StackPanel>
<x:AnotherButton/>
</StackPanel>
</Window>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.