[英]Transform SOAP Request with XSLT | For Each Loop Issue
我有一个类似于以下内容的SOAP请求;
<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>
<GetCountriesResponse xmlns="url">
<GetCountriesResult>
<ExtendedOptionItem>
<Value>GB</Value>
<Description>United Kingdom</Description>
<Active>true</Active>
<IsDefault>true</IsDefault>
<Order>0</Order>
</ExtendedOptionItem>
<ExtendedOptionItem>
<Value>GB</Value>
<Description>United Kingdom</Description>
<Active>true</Active>
<IsDefault>true</IsDefault>
<Order>0</Order>
</ExtendedOptionItem>
</GetCountriesResult>
</GetCountriesResponse>
</soap:Body>
</soap:Envelope>
目前,我的XSLT专门针对“描述”节点。 我想做的是为每个“ ExtendedOptionItem”提取描述。
我写了一些XSLT,需要用分号分隔每个描述。
当只有一个“ ExtendedOptionItem”时,此XSLT绝对可以正常工作。 但是,当有多个项目时,XML不会转换。
请您检查一下我的XSLT并评估我出了什么问题;
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<xsl:output method="xml" omit-xml-declaration="no" encoding="utf-8" indent="yes" />
<xsl:template match="/">
<xsl:for-each xmlns:n="url" select="n:ExtendedOptionItem">
<xsl:value-of select="n:Description" />;</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
非常感谢
更新;
工作流引擎将SOAP响应修改为如下所示;
<ExtendedOptionItem xmlns="url"><Value>GB</Value><Description>United Kingdom</Description><Active>true</Active><IsDefault>true</IsDefault><Order>0</Order></ExtendedOptionItem><ExtendedOptionItem xmlns="url"><Value>AF</Value><Description>Afghanistan</Description><Active>true</Active><IsDefault>false</IsDefault><Order>0</Order></ExtendedOptionItem><ExtendedOptionItem xmlns="url"><Value>AX</Value><Description>Åland Islands</Description><Active>true</Active><IsDefault>false</IsDefault><Order>0</Order></ExtendedOptionItem>
当只有一个“ ExtendedOptionItem”时,此XSLT绝对可以正常工作。
不,不是。
问题是您的模板与/
根节点匹配-而ExtendedOptionItem
不是/
根节点的子级。 结果,您:
<xsl:for-each xmlns:n="url" select="n:ExtendedOptionItem">
什么都不选择。 尝试将其更改为:
<xsl:for-each xmlns:n="url" select="//n:ExtendedOptionItem">
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.