2
在給定的非常簡單,標準配置:如何刪除具有與使用XSLT給定的屬性值不同的節點?
<?xml version="1.0" encoding="utf-8" ?>
<configuration xmlns:env="urn:schemas-test-env">
<appSettings>
<add key="Name" value="Value" />
<add key="Name" value="Value" env:name="Dev" />
<add key="Name" value="Value" env:name="QA" />
</appSettings>
<!-- rest of the config -->
</configuration>
我想用XSLT刪除所有節點<add />
哪裏@env:name != $env
?我的主要問題是將配置的其餘部分保持原樣。
我到目前爲止有:
<!-- populated by inline C# code -->
<xsl:variable name="env" select="code:GetEnvironment()" />
<!-- Leave as is -->
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()" />
</xsl:copy>
</xsl:template>
<!-- Remove non-matching nodes -->
<xsl:template match="configuration/appSettings/add">
???
</xsl:template>
我有一個多個分支:
<xsl:choose>
<xsl:when test="not(@env:name)">
<xsl:value-of select="'no env'" />
</xsl:when>
<xsl:when test="./@env:name = $env">
<xsl:value-of select="'Env eq var'" />
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="'Env neq var'" />
</xsl:otherwise>
</xsl:choose>
不幸的是,2.0在Visual Studio XSLT Debug中拋出異常「操作可能會破壞運行時」。 – abatishchev 2013-03-08 05:13:36
我想實現一個相反的事情:當env = Dev時,只留下env-empty和env-equal給定,即「」和「Dev」。反之亦然。所以我使用'not(@env:name!= $ env)',它完美。謝謝! – abatishchev 2013-03-08 05:16:53
[在線](http://www.xsltcake.com/slices/8B1eKo)2.0版本不起作用。你不知道爲什麼會發生? – abatishchev 2013-03-08 05:17:49