【发布时间】:2016-06-10 16:26:59
【问题描述】:
只是想知道是否可以使用 XSLT 转换文件将 XML 从一种标准转换为另一种标准。我正在尝试将 FGDC 元数据转换为 ISO 19139。我有一个应该能够转换它的 XSLT。
如果可能的话,下面的代码是否缺少我的东西?
from lxml import etree
f_xml = 'U:\\PROJECTS\\FGDC2ISO\\A08727.mxd.xml'
f_xsl = 'U:\\PROJECTS\\FGDC2ISO\\ISO2.xslt'
f_out = 'U:\\PROJECTS\\FGDC2ISO\\A08727_ISO.mxd.xml'
transform = etree.XSLT(etree.parse(f_xsl))
result = transform(etree.parse(f_xml))
result.write(f_out)
这里是 xslt 的链接 现在可以编辑链接了:
XSML 文件示例:
<?xml version="1.0" encoding="utf-8" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:gco="http://www.isotc211.org/2005/gco" xmlns:gmd="http://www.isotc211.org/2005/gmd" xmlns:gmi="http://www.isotc211.org/2005/gmi" xmlns:gmx="http://www.isotc211.org/2005/gmx" xmlns:gsr="http://www.isotc211.org/2005/gsr" xmlns:gss="http://www.isotc211.org/2005/gss" xmlns:gts="http://www.isotc211.org/2005/gts" xmlns:gml="http://www.opengis.net/gml/3.2" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:vmf="http://www.altova.com/MapForce/UDF/vmf" xmlns:fn="http://www.w3.org/2005/xpath-functions" xmlns:grp="http://www.altova.com/Mapforce/grouping" xmlns="http://www.isotc211.org/2005/gmi" version="2.0" exclude-result-prefixes="fn grp vmf xs xsi xsl">
<xsl:template name="vmf:vmf1_inputtoresult">
<xsl:param name="input" select="()"/>
<xsl:choose>
<xsl:when test="$input='POINT'">
<xsl:value-of select="'point'"/>
</xsl:when>
<xsl:when test="$input='PIXEL'">
<xsl:value-of select="'point'"/>
</xsl:when>
<xsl:when test="$input='GRID CELL'">
<xsl:value-of select="'area'"/>
</xsl:when>
<xsl:when test="$input='VOXEL'">
<xsl:value-of select="'area'"/>
【问题讨论】:
-
样式表链接失效。
-
对不起,我已经编辑了链接。现在应该可以工作了。我一直遇到错误 lxml.etree.XSLTParseError: Invalid expression
标签: xml python-2.7 xslt lxml