Xml SOAP响应转换为CSV 12345 产品名称 12222 卷积和多项式相乘 常规贷款 真的 假的 1111 2222 ....... ------------------------------------ ---------------------------------------------------- , , , , ,
基本上,我正在尝试编写XSL来将所有这些“产品”内部属性值转换为CSV格式。我已经在努力克服使用名称空间的困难,但仍然无法以完美的格式编写,有时下一行会出现样式,如果我尝试使用通用名称空间,那么问题就在于无法读取AdditionalAttributes值。 这方面的任何帮助都会很好 期望输出为 所有标记内部属性以CSV格式排列,顺序为“”Xml SOAP响应转换为CSV 12345 产品名称 12222 卷积和多项式相乘 常规贷款 真的 假的 1111 2222 ....... ------------------------------------ ---------------------------------------------------- , , , , ,,xml,xslt,soap,csv,Xml,Xslt,Soap,Csv,基本上,我正在尝试编写XSL来将所有这些“产品”内部属性值转换为CSV格式。我已经在努力克服使用名称空间的困难,但仍然无法以完美的格式编写,有时下一行会出现样式,如果我尝试使用通用名称空间,那么问题就在于无法读取AdditionalAttributes值。 这方面的任何帮助都会很好 期望输出为 所有标记内部属性以CSV格式排列,顺序为“” <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/e
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Body>
<ns0:DataResponse xmlns:ns0="http://somenamspace/v1.0">
<ns0:ResponseId>
<ns0:RequestID>12345</ns0:RequestID>
</ns0:ResponseId>
<ns0:Payload>
<ns1:Product xmlns:ns1="http://anothernamespace/v1.x">
<ns1:ProductName>productName</ns1:ProductName>
<ns1:ProductIdentifier>12222</ns1:ProductIdentifier>
<ns1:ProdInst>
<ns1:Type>Conv</ns1:Type>
<ns1:Descr>Conventional Loan</ns1:Descr>
<ns1:AllowedTypes>
<ns1:ScheduleSchedule>true</ns1:ScheduleSchedule>
</ns1:AllowedTypes>
<ns1:prdExist>false</ns1:prdExist>
<ns1:AdditionalAttributes>
<ns1:AdditionalAttribute name="gura" value="C"/>
</ns1:AdditionalAttributes>
</ns1:ProdInst>
<ns1:ProductGroups>
<ns1:ProductGroupName>1111</ns1:ProductGroupName>
<ns1:ProductGroupName>2222</ns1:ProductGroupName>
</ns1:ProductGroups>
</ns1:Product>
<ns1:Product>
.......
</ns1:Product>
</ns0:Payload>
</ns0:DataResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
------------------------------------
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:ns0="http://somenamespace/v1.0"
xmlns:ns1="http://anothernamespace/v1.x"
exclude-result-prefixes="ns1">
<xsl:output omit-xml-declaration="yes" indent="no" method="text"/>
<xsl:template match="ns1:Products">
<xsl:value-of select="."/>
</xsl:template>
</xsl:stylesheet>
----------------------------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:ns1="http://namespace/v1.x"
exclude-result-prefixes="ns1">
<xsl:output omit-xml-declaration="yes" indent="no" method="text"/>
<xsl:template match="/">
<xsl:for-each select="ns1:Product">
<xsl:value-of select="ns1:ProductName" />
<xsl:text>,</xsl:text>
<xsl:value-of select="ns1:ProdInst/ns1:Type" />
<xsl:text>,</xsl:text>
<xsl:value-of select="ns1:ProdInst/ns1:Descr" />
<xsl:text>,</xsl:text>
<xsl:value-of select="ns1:ProdInst/ns1:AdditionalAttributes/@gura" />
<xsl:text>,</xsl:text>
<xsl:for-each select="ns1:ProductGroups">
<xsl:value-of select="."/>
</xsl:for-each>,
</xsl:for-each>
</xsl:template>
我已经尝试了上面的方法,至少在同一行中得到了所有的结果,但仍然没有逗号分隔,也没有包括“AdditionalAttributes”。有人能帮忙吗?请查看此解决方案: XSLT:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:ns0="http://somenamspace/v1.0"
xmlns:ns1="http://anothernamespace/v1.x"
exclude-result-prefixes="ns1">
<xsl:output method="text" indent="no"/>
<xsl:strip-space elements="*"/>
<xsl:template match="/">
<xsl:apply-templates select="ns1:Product"/>
</xsl:template>
<xsl:template match="ns1:Product">
<xsl:value-of select="*"/>
<xsl:apply-templates select="ns1:ProdInst"/>
<xsl:apply-templates select="ns1:ProductGroups"/>
</xsl:template>
<xsl:template match="ns1:ProdInst">
<xsl:value-of select="."/>
<xsl:apply-templates select="ns1:AllowedTypes"/>
<xsl:apply-templates select="ns1:AdditionalAttributes"/>
</xsl:template>
<xsl:template match="ns1:AllowedTypes">
<xsl:value-of select="."/>
</xsl:template>
<xsl:template match="ns1:AdditionalAttributes">
<xsl:for-each select="@*">
<xsl:copy-of select="." />
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:ns0="http://somenamspace/v1.0" xmlns:ns1="http://anothernamespace/v1.x"
exclude-result-prefixes="ns1">
<xsl:output method="text" indent="no"/>
<xsl:strip-space elements="*"/>
<xsl:template match="/">
<xsl:for-each select="//ns1:Product">
<xsl:call-template name="getProduct">
<xsl:with-param name="Product" select="self::*"/>
</xsl:call-template>
<xsl:text>
</xsl:text>
</xsl:for-each>
</xsl:template>
<xsl:template name="getProduct">
<xsl:param name="Product"/>
<xsl:variable name="ProductContent">
<xsl:for-each select="$Product/*">
<xsl:choose>
<xsl:when test="*">
<xsl:call-template name="getChild">
<xsl:with-param name="Child" select="*"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:if test="@*">
<xsl:for-each select="@*">
<xsl:value-of select="."/>
<xsl:text>,</xsl:text>
</xsl:for-each>
<xsl:text>,</xsl:text>
</xsl:if>
<xsl:value-of select="."/>
<xsl:text>,</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</xsl:variable>
<xsl:value-of select="substring($ProductContent,0,string-length($ProductContent))"/>
</xsl:template>
<xsl:template name="getChild">
<xsl:param name="Child"/>
<xsl:for-each select="$Child/node()">
<xsl:choose>
<xsl:when test="* and not(@*)">
<xsl:call-template name="getChild">
<xsl:with-param name="Child" select="*"/>
</xsl:call-template>
</xsl:when>
<xsl:when test="text()">
<xsl:value-of select="."/>
<xsl:text>,</xsl:text>
</xsl:when>
<xsl:when test="*">
<xsl:for-each select="@*">
<xsl:value-of select="."/>
<xsl:text>,</xsl:text>
</xsl:for-each>
<xsl:call-template name="getChild">
<xsl:with-param name="Child" select="*"/>
</xsl:call-template>
</xsl:when>
<xsl:when test="not(*) and @*">
<xsl:for-each select="@*">
<xsl:value-of select="."/>
<xsl:text>,</xsl:text>
</xsl:for-each>
</xsl:when>
<xsl:otherwise>
<xsl:if test="@*">
<xsl:for-each select="@*">
<xsl:value-of select="."/>
<xsl:text>,</xsl:text>
</xsl:for-each>
<xsl:text>,</xsl:text>
</xsl:if>
<xsl:value-of select="."/>
<xsl:text>,</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
<xsl:if test="$Child/@* and not($Child/node())">
<xsl:for-each select="$Child/@*">
<xsl:value-of select="."/>
<xsl:text>,</xsl:text>
</xsl:for-each>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
向我们展示一个您希望接收的示例。我只需要打印CSV格式中节点的所有值,而不管它是节点还是属性,甚至是嵌套的。产品名称,12222,Conv,常规借阅,true,false,C,11112222产品名称112223,Conv1,常规借阅1,true,false,C111112222:谢谢Navin,这会产生编译错误JAXPSAXProcessorInvoker-在“self::*/*和not(self:*/@*)”中出现语法错误。你可以帮助脚本打印每行的“交易”值吗。我几乎成功了,但我真的不知道如何去掉每个“交易”值中“最后一个值”后面的最后一个逗号。
productName,12222,Conv,Conventional Loan,true,false,gura,C,1111,2222
produ222222222ctName,12222,Conv,Conventional Loan,true,false,gura,C,1111,2222