【发布时间】:2018-06-27 11:34:14
【问题描述】:
我有一个从 SharePoint 生成的 xml,我需要提取一些数据并生成一个简化的 xml
这是我的原始(简化)源文件
<?xml version="1.0" encoding="utf-8"?>
<feed xml:base="http://itkm.gamesacorp.com/applications/_api/" xmlns="http://www.w3.org/2005/Atom" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns:georss="http://www.georss.org/georss" xmlns:gml="http://www.opengis.net/gml">
<id>f8a19240-e319-454a-b4a6-fab8e3470c8d</id>
<title />
<updated>2018-01-17T15:13:15Z</updated>
<entry m:etag=""53"">
<id>Web/Lists(guid'fe244c05-99f9-4b69-8727-46327122b245')/Items(1)</id>
<content type="application/xml">
<m:properties>
<d:Codigo>0002</d:Codigo>
<d:App_x0020_name>GOT</d:App_x0020_name>
</m:properties>
</content>
</entry>
<entry m:etag=""49"">
<id>Web/Lists(guid'fe244c05-99f9-4b69-8727-46327122b245')/Items(3)</id>
<content type="application/xml">
<m:properties>
<d:Codigo>0006</d:Codigo>
<d:App_x0020_name>ALTAIR</d:App_x0020_name>
</m:properties>
</content>
</entry>
</feed>
这是我的 xslt
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output encoding="UTF-8" indent="yes" method="xml" standalone="no" omit-xml-declaration="no"/>
<xsl:template match="feed">
<Applications>
<xsl:for-each select="entry">
<App>
<Code><xsl:value-of select="content/properties/Codigo"/></Code>
<Name><xsl:value-of select="content/properties/App_x0020_name"/></Name>
<Uri><xsl:value-of select="id"/></Uri>
</App>
</xsl:for-each>
</Applications>
</xsl:template>
</xsl:stylesheet>
如果我在 xml 和 xslt 中都省略了命名空间,结果符合预期,但我需要 xlst 使用命名空间,但我不知道 xslt 中包含哪些命名空间(以及如何包含)
这是适用于我的修改后的 xml,请注意我删除了对命名空间的所有引用:
<?xml version="1.0" encoding="utf-8"?>
<feed>
<id>f8a19240-e319-454a-b4a6-fab8e3470c8d</id>
<title />
<updated>2018-01-17T15:13:15Z</updated>
<entry etag=""53"">
<id>Web/Lists(guid'fe244c05-99f9-4b69-8727-46327122b245')/Items(1)</id>
<content type="application/xml">
<m:properties>
<Codigo>0002</Codigo>
<App_x0020_name>GOT</App_x0020_name>
</m:properties>
</content>
</entry>
</feed>
如何使用 xslt 来使用命名空间?
【问题讨论】: