【发布时间】:2017-05-25 05:30:20
【问题描述】:
我有一些用于修改 xml 文档的 xslt 文件。 ArcGIS Desktop 10.4 的元数据 xml。目前我将它们链接在一起以获得所需的输出xml(将xslt 1应用于输入xml,然后将xslt 2应用于第一步的输出,然后应用xslt 3)。虽然这很好用,但我想将我的三张纸合二为一。我已经尝试过,但是当我组合它们时,每个部分都会“覆盖”最后一个。
这会删除所有不需要的节点。
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes" omit-xml-declaration="no" />
<!-- process the metadata using the templates below -->
<xsl:template match="/">
<xsl:apply-templates select="node() | @*" />
</xsl:template>
<!-- copy all metadata conent -->
<xsl:template match="node() | @*" priority="0">
<xsl:copy>
<xsl:apply-templates select="node() | @*" />
</xsl:copy>
</xsl:template>
<!-- If the element exists, remove it -->
<xsl:template match="resConst | Process | mdContact | citRespParty | idPoC | idCredit | prcStep | rpIndName | rpOrgName | rpPosName | role | displayName | rpCntInfo | searchKeys | themeKeys" />
</xsl:stylesheet>
这增加了一些使用限制。
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes" omit-xml-declaration="no" />
<!-- process the metadata using the templates below -->
<xsl:template match="/">
<xsl:apply-templates select="node() | @*" />
</xsl:template>
<!-- copy all metadata conent -->
<xsl:template match="node() | @*" priority="0">
<xsl:copy>
<xsl:apply-templates select="node() | @*" />
</xsl:copy>
</xsl:template>
<!-- Add Nodes -->
<xsl:template match="dataIdInfo">
<xsl:copy>
<xsl:copy-of select="node() | @*" />
<resConst>
<Consts>
<useLimit>CONFIDENTIAL AND PROPRIETARY INFORMATION</useLimit>
</Consts>
</resConst>
<searchKeys>
<keyword>keyword</keyword>
</searchKeys>
<themeKeys>
<keyword>keyword</keyword>
</themeKeys>
<idCredit>our org</idCredit>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
最后,这个增加了一个联系点。
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes" omit-xml-declaration="no" />
<!-- process the metadata using the templates below -->
<xsl:template match="/">
<xsl:apply-templates select="node() | @*" />
</xsl:template>
<!-- copy all metadata conent -->
<xsl:template match="node() | @*" priority="0">
<xsl:copy>
<xsl:apply-templates select="node() | @*" />
</xsl:copy>
</xsl:template>
<!-- Add Nodes -->
<xsl:template match="idCitation">
<xsl:copy>
<xsl:copy-of select="node() | @*" />
<citRespParty>
<rpIndName>name</rpIndName>
<rpOrgName>org</rpOrgName>
<rpPosName>role</rpPosName>
<role>
<RoleCd value="007" />
</role>
<rpCntInfo>
<cntAddress addressType="">
<delPoint>street number</delPoint>
<city>city</city>
<adminArea>state</adminArea>
<postCode>zip</postCode>
<eMailAdd>email</eMailAdd>
<country>country</country>
</cntAddress>
<cntPhone>
<voiceNum tddtty="">phone number</voiceNum>
</cntPhone>
</rpCntInfo>
</citRespParty>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
示例输入: http://textuploader.com/d92rd
示例输出: http://textuploader.com/d92r6
示例节点更改:您将看到 resConsts 是节点被完全删除。然后在与我们的组织使用限制文本相同的 XPath 中添加一个新的 resConsts 节点。
这是基于我的流程的 Esri 站点: http://desktop.arcgis.com/en/arcmap/10.3/manage-data/metadata/editing-metadata-for-many-arcgis-items.htm
【问题讨论】:
-
您确定这是个好主意吗?做相反的事情通常被认为是一种好的做法:将复杂的转换分解为由单独、简单、可重用的步骤组成的管道。
-
不,我不确定这是个好主意。我以前从未使用过 xslt。我在想将它们结合起来会更有效/更专业。现在我用 python 把它们锁起来了。