【发布时间】:2016-11-08 21:50:30
【问题描述】:
我正在尝试使用 xslt 将 xml 从一个 xml 转换为另一个,但无法得到错误。
我的输入是:
<?xml version = "1.0"?>
<queryResponse xmlns="urn:sfobject.sfapi.successfactors.com" xmlns:ns2="urn:fault.sfapi.successfactors.com">
<result>
<sfobject>
<id>1791
</id>
<type>CompoundEmployee
</type>
<execution_timestamp>2016-11-08T06:38:48.000Z
</execution_timestamp>
<version_id>1611P0
</version_id>
</sfobject>
<sfobject>
<id>122
</id>
<type>Simple
</type>
<execution_timestamp>2016-11-08T08:32:18.000Z
</execution_timestamp>
<version_id>16120
</version_id>
</sfobject>
<numResults>1
</numResults>
<hasMore>true
</hasMore>
<querySessionId>5f619648-548a-43ec-8119-627094f927a5
</querySessionId>
</result>
</queryResponse>
XSLT 是:
<?xml version = "1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xsl:template match="result">
<calls>
<xsl:for-each select = "sfobject">
<call>
<id>
<xsl:value-of select = "id"/>
</id>
<type>
<xsl:value-of select = "type"/>
</type>
</call>
</xsl:for-each>
</calls>
</xsl:template>
</xsl:stylesheet>
我收到如下输出:
1791 CompoundEmployee 2016-11-08T06:38:48.000Z 1611P0 122 简单
2016-11-08T08:32:18.000Z 16120 1 对
5f619648-548a-43ec-8119-627094f927a5
基本上,我没有得到标签。我打算得到如下输出:
<calls>
<call>
<id>123</id>
<type>CompoundEmployee</type>
</call>
</calls>
【问题讨论】:
-
我将
<call>标记更改为正确的结束标记</call>。这是复制/粘贴错误吗? -
就像你之前的一千个 SO 用户一样,你已经陷入了默认命名空间陷阱。
-
是的,结束标签是复制粘贴错误。