需要帮助创建XSLT,我有源XML和目标XML
我正在尝试为源XML编写XSLT文档,我也有tragetXML(它应该是什么样子的) 我的消息来源如下:需要帮助创建XSLT,我有源XML和目标XML,xml,xslt,Xml,Xslt,我正在尝试为源XML编写XSLT文档,我也有tragetXML(它应该是什么样子的) 我的消息来源如下: <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> &l
<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)
我一直在尝试编写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>
--我知道这是不对的,但我只是想做点事情
谢谢您需要为源文档使用的每个名称空间分配一个前缀,并在对源文档中的元素寻址时使用适当的前缀。下面是对样式表的更正:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:dir="http://schemas.microsoft.com/sharepoint/soap/directory/"
exclude-result-prefixes="soap dir">
<xsl:output method="xml" version="1.0" encoding="utf-8" indent="yes"/>
<xsl:template match="/">
<xsl:apply-templates select="soap:Envelope/soap:Body/dir:a/dir:b/dir:c/dir:d"/>
</xsl:template>
<xsl:template match="dir:d">
<d>
<xsl:for-each select="dir:e">
<e>
<xsl:value-of select="@MemberID"/>
</e>
</xsl:for-each>
</d>
</xsl:template>
</xsl:stylesheet>
这将产生以下结果:
<?xml version="1.0" encoding="utf-8"?>
<d>
<e>1</e>
<e>2</e>
<e>3</e>
</d>
1.
2.
3.
当然,您可以将其简化为:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:dir="http://schemas.microsoft.com/sharepoint/soap/directory/"
exclude-result-prefixes="soap dir">
<xsl:output method="xml" version="1.0" encoding="utf-8" indent="yes"/>
<xsl:template match="/">
<d>
<xsl:for-each select="soap:Envelope/soap:Body/dir:a/dir:b/dir:c/dir:d/dir:e">
<e>
<xsl:value-of select="@MemberID"/>
</e>
</xsl:for-each>
</d>
</xsl:template>
</xsl:stylesheet>
要实现所需的输出,请更改:
<e>
<xsl:value-of select="@MemberID"/>
</e>
致:
为什么您的样式表包含一个literal
元素,而您所需的输出却没有另外,您尝试的主要问题是您忽略了源文档的名称空间。
<e>
<xsl:value-of select="@MemberID"/>
</e>
<e ID="{@MemberID}"/>