我在输入请求下面有这个。我们将获得近10个包含Book和Date信息的标签<shop>
。我希望每个信息都在标签之间。我应该如何用xslt编写它?
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:p="http://www.blah.com">
<soapenv:Header/>
<soapenv:Body>
<p:order>
<p:shop>
<p:Book>Guru</p:Book>
<p:date>12-2-2020</p:date>
<p:Book>jungle</p:Book>
<p:date>13-1-2023</p:date>
<p:Book>Sports</p:Book>
<p:date>13-1-2023</p:date>
</p:shop>
</p:order>
</soapenv:Body>
</soapenv:Envelope>
预期产量:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:p="http://www.blah.com">
<soapenv:Header/>
<soapenv:Body>
<p:order>
<p:shop>
<p:Author>Guru</p:Author>
<p:startdate>12-2-2020</p:startdate>
<p:shop>
<p:Author>jungle</p:Author>
<p:startdate>13-1-2023<p:/startdate>
<p:shop>
<p:Author>Sports</p:Author>
<p:startdate>13-1-2023</p:startdate>
</p:shop>
</p:order>
<e:shop>
</soapenv:Body>
</soapenv:Envelope>
我的xslt:
<xsl:for-each select="//Order">
<xsl:value-of select="following-sibling::date[1]"/>
<p:Author>
<xsl:value-of select="$Book"/>
</p:Author>
<p:StartDate>
<xsl:value-of select="$date"/>
</p:StartDate>
</xsl:for-each>
您显示的输出不是格式正确的XML。假设您要获得以下输出:
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:p="http://www.blah.com">
<soapenv:Header/>
<soapenv:Body>
<p:order>
<p:shop>
<p:Book>Guru</p:Book>
<p:date>12-2-2020</p:date>
</p:shop>
<p:shop>
<p:Book>jungle</p:Book>
<p:date>13-1-2023</p:date>
</p:shop>
<p:shop>
<p:Book>Sports</p:Book>
<p:date>13-1-2023</p:date>
</p:shop>
</p:order>
</soapenv:Body>
</soapenv:Envelope>
尝试:
XSLT 1.0
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:p="http://www.blah.com">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:strip-space elements="*"/>
<!-- identity transform -->
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="p:shop">
<xsl:for-each select="p:Book">
<p:shop>
<xsl:copy-of select=". | following-sibling::p:date[1]"/>
</p:shop>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句