下面是输入XML,希望它使用XSLT在其他输出XML中进行转换。
我的输入XML如下,
<?xml version="1.0" encoding="utf-8"?>
<AppSettings>
<Plugins>
<AssemblyName>Version=5.0, Culture=neutral, PublicKeyToken=null</AssemblyName>
<TypeName>AAA</TypeName>
<Version>?</Version>
<Configuration>
<AppData xmlns="http://tempuri.org/AppData.xsd">
<Readers>
<Id>1</Id>
<Port>2500</Port>
<Type>M100</Type>
</Readers>
</AppData>
</Configuration>
</Plugins>
<Plugins>
<AssemblyName>Version=5.0, Culture=neutral, PublicKeyToken=null</AssemblyName>
<TypeName>BBB</TypeName>
<Version>?</Version>
<Configuration>
<AppData xmlns="http://tempuri.org/AppData.xsd">
<Readers>
<Id>2</Id>
<Port>3500</Port>
<Type>M200</Type>
</Readers>
</AppData>
</Configuration>
</Plugins>
</AppSettings>从上面的XML中,我希望选择具有TypeName "BBB“的"Plugins”节点,并使用它的子节点获得低于输出的结果。
<?xml version="1.0" encoding="utf-8"?>
<AppSettings>
<Inputs>
<PlugInType>M200</PlugInType>
<Port>3500</Port>
</Inputs>
</AppSettings>我尝试使用下面的XSLT,但没有获得所需的输出。
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="/">
<AppSettings>
<Inputs>
<xsl:for-each select="AppSettings">
<xsl:for-each select="//Plugins[TypeName=BBB]">
<xsl:for-each select="Configuration/AppData/Readers">
<PlugInType>
<xsl:value-of select="Type"/>
</PlugInType>
<Port>
<xsl:value-of select="Port"/>
</Port>
</xsl:for-each>
</xsl:for-each>
</xsl:for-each>
</Inputs>
</AppSettings>
</xsl:template>
让我知道我哪里出错了
发布于 2014-04-30 14:00:02
我想你想
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
xmlns:df="http://tempuri.org/AppData.xsd" exclude-result-prefixes="df">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="/">
<AppSettings>
<Inputs>
<xsl:for-each select="AppSettings//Plugins[TypeName='BBB']/Configuration/df:AppData/df:Readers">
<PlugInType>
<xsl:value-of select="df:Type"/>
</PlugInType>
<Port>
<xsl:value-of select="df:Port"/>
</Port>
</xsl:for-each>
</Inputs>
</AppSettings>
</xsl:template>来处理XML中的xmlns="http://tempuri.org/AppData.xsd"。
https://stackoverflow.com/questions/23389779
复制相似问题