【发布时间】:2014-09-28 14:25:46
【问题描述】:
我正在尝试为源 XML 编写 XSLT 文档,而且我也有 Traget XML(它应该是什么样子)
我的来源看起来像:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<a xmlns="http://schemas.microsoft.com/sharepoint/soap/directory/">
<b>
<c>
<d>
<e MemberID="1" />
<e MemberID="2" />
<e MemberID="3" />
</d>
</c>
</b>
</a>
</soap:Body>
</soap:Envelope>
我想要实现的是(目标 XML)
<d>
<e ID="1" />
<e ID="2" />
<e ID="3" />
</d>
我一直在尝试编写我的 XSLT,但无法正常工作。我一直在使用一些在线工具,在那里我提供了我的源代码并编写了 XSLT,但我没有得到任何结果。 (从未在 XSLT 中工作过)
有人可以帮我写这篇文章或指出我的写作方向吗?
我试过的是:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<xsl:apply-templates select="a/b/c/d"/>
</xsl:template>
<xsl:template match="d">
<d>
<xsl:for-each select="e">
<e>
<xsl:value-of select="@MemberID"/> -- I know its wrong, but just want something to work
</e>
</xsl:for-each>
</d>
</xsl:template>
</xsl:stylesheet>
谢谢
【问题讨论】:
-
为什么您的样式表包含文字
<Members>元素,而您所需的输出却没有? --附言您尝试的主要问题是您忽略了源文档的 命名空间。