【问题标题】:Xml stylesheet doesn't work because of namespace由于命名空间,XML 样式表不起作用
【发布时间】:2014-11-28 13:01:50
【问题描述】:

我想得到以下的全名,所以结果应该是“Root Administratoren”

<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
	<GetAllGroupsOfUserResponse xmlns="http://fuu/fuu/fuu/">
		<GetAllGroupsOfUserResult>
			<Group>
				<DataId>11</DataId>
				<ObjectGuid>31ea4ee1-cf85-44ac-846e-6ef58542af2c</ObjectGuid>
				<FullName>Root Administratoren</FullName>
			</Group>
		</GetAllGroupsOfUserResult>
	</GetAllGroupsOfUserResponse>
</soap:Body>
</soap:Envelope>`

我正在使用这个 XML 样式表

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl" xmlns:tmp="http://tempuri.org/">
	<xsl:output method="xml" indent="yes" />
	<xsl:template match="/">
		<Result>
			<xsl:for-each select="ArrayOfGroup/Group">
			<FullName>
				<xsl:value-of select="FullName" />
			</FullName>
			</xsl:for-each>
		</Result>
	</xsl:template>
</xsl:stylesheet>

但是当我删除它工作的命名空间时我没有得到任何结果,但是 xml 必须保持这种方式。 感谢您的帮助

问候 亚历克斯

【问题讨论】:

    标签: xml web-services soap namespaces


    【解决方案1】:

    为默认命名空间添加一个新前缀,并将其与 XPath 中的每个元素一起使用。 此外,添加 // 以获取所有 ArrayOfGroup 元素。

     <xsl:stylesheet version="1.0" 
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
    xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl" xmlns:tmp="http://tempuri.org/"
    xmlns:fuu="http://fuu/fuu/fuu/"
    >
    	<xsl:output method="xml" indent="yes" />
    	<xsl:template match="/">
    		<Result>
    			<xsl:for-each select="//fuu:ArrayOfGroup/fuu:Group">
    			<FullName>
    				<xsl:value-of select="fuu:FullName" />
    			</FullName>
    			</xsl:for-each>
    		</Result>
    	</xsl:template>
    </xsl:stylesheet>

    【讨论】:

      猜你喜欢
      • 2020-05-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-09-16
      • 1970-01-01
      相关资源
      最近更新 更多