任何人都可以帮助通过 XSLT 转换我的 xml。我是这个 xslt 的新手,无法让它工作。
这是示例输入 xml 文件:
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<TCXML xmlns="http://www.tcxml.org/Schemas/TCXMLSchema">
<BOMLine bl_appearance_path_node="" bl_attachments="#id13 #id15 #id20 #id21 #id22 #id3" bl_bomview="" bl_bomview_rev="" bl_gde_bomview_rev="" bl_item="#id7" bl_real_occurrence="" bl_revision="#id8" elemId="id61">
<GSIdentity elemId="id2" label="_RnrSUKuM1CaiD"/>
</BOMLine>
<DrawingSheet creation_date="2012-06-05T09:27:19Z" date_released="2012-06-05T09:25:33Z" ead_paragraph="" elemId="id69" format_used="BINARY" gov_classification="" highest_rev_prop="1" ip_classification="" keep_limit_prop="3" last_mod_date="2012-06-05T09:27:20Z" license_list="" object_desc="" object_name="Sheet 1" owning_organization="">
<GSIdentity elemId="id24" label="RoL9sTu6BT4jNA"/>
</DrawingSheet>
<DrawingSheet creation_date="2012-06-05T09:28:44Z" date_released="2012-06-05T09:25:33Z" ead_paragraph="" elemId="id70" format_used="BINARY" gov_classification="" highest_rev_prop="1" ip_classification="" keep_limit_prop="3" last_mod_date="2012-06-05T09:28:45Z" license_list="" object_desc="" object_name="Sheet 1" owning_organization="">
<GSIdentity elemId="id25" label="RoO9sTvgBT4jNA"/>
</DrawingSheet>
<DrawingSheet creation_date="2012-06-05T09:29:29Z" date_released="2012-06-05T09:25:33Z" ead_paragraph="" elemId="id71" format_used="BINARY" gov_classification="" highest_rev_prop="1" ip_classification="" keep_limit_prop="3" last_mod_date="2012-06-05T09:29:29Z" license_list="" object_desc="" object_name="Sheet 1" owning_organization="">
<GSIdentity elemId="id26" label="RoO9sTfVBT4jNA"/>
</DrawingSheet>
<IMAN_Drawing elemId="id78" owning_site="#id4" primary_object="#id21" secondary_object="#id25" user_data="">
<GSIdentity elemId="id50" label="R8D9sTvgBT4jNA"/>
</IMAN_Drawing>
<IMAN_Drawing elemId="id79" owning_site="#id4" primary_object="#id22" secondary_object="#id26" user_data="">
<GSIdentity elemId="id56" label="R8D9sTfVBT4jNA"/>
</IMAN_Drawing>
<IMAN_Drawing elemId="id80" owning_site="#id4" primary_object="#id20" secondary_object="#id24" user_data="">
<GSIdentity elemId="id44" label="R8A9sTu6BT4jNA"/>
</IMAN_Drawing>
<UGPART creation_date="2012-06-05T09:25:30Z" date_released="2012-06-05T09:25:33Z" ead_paragraph="" elemId="id117" format_used="PART" gov_classification="" highest_rev_prop="1" ip_classification="" keep_limit_prop="3" last_mod_date="2012-06-05T09:25:34Z" license_list="" object_desc="dwg3" object_name="dwg3" owning_organization="">
<GSIdentity elemId="id21" label="RXM9sPifBT4jNA"/>
</UGPART>
<UGPART creation_date="2012-06-05T09:25:30Z" date_released="2012-06-05T09:25:33Z" ead_paragraph="" elemId="id118" format_used="PART" gov_classification="" highest_rev_prop="1" ip_classification="" keep_limit_prop="3" last_mod_date="2012-06-05T09:25:33Z" license_list="" object_desc="dwg1" object_name="dwg1" owning_organization="">
<GSIdentity elemId="id20" label="R3K9sPifBT4jNA"/>
</UGPART>
<UGPART creation_date="2012-06-05T09:25:28Z" date_released="2012-06-05T09:25:33Z" ead_paragraph="" elemId="id119" format_used="PART" gov_classification="" highest_rev_prop="1" ip_classification="" keep_limit_prop="3" last_mod_date="2012-06-05T09:25:34Z" license_list="" object_desc="dwg2" object_name="dwg2" owning_organization="">
<GSIdentity elemId="id22" label="xuO9sPifBT4jNA"/>
</UGPART>
</TCXML>
在这个 xml 文件中有 3 个 IMAN_Drawing 、3 个图纸和 3 个 UGPART 标签。例如 ,
<IMAN_Drawing elemId="id78" owning_site="#id4" primary_object="#id21" secondary_object="#id25" user_data="">
<GSIdentity elemId="id50" label="R8D9sTvgBT4jNA"/>
</IMAN_Drawing>
所以我想复制UGPART(在这种情况下为primary_object id21)object_name 并附加到DrawingSheet(在这种情况下为secondary_object id25)object_name。所以最终 DrawingSheet 名称将是 UGPART 的 object_name _ DrawingSheet 的 object_name。对于这种情况,DrawingSheet object_name 将更新为 dwg3_Sheet 1
所以最后我想为我的 input.xml 输出 xml,如下所示。
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<TCXML xmlns="http://www.tcxml.org/Schemas/TCXMLSchema">
<BOMLine bl_appearance_path_node="" bl_attachments="#id13 #id15 #id20 #id21 #id22 #id3" bl_bomview="" bl_bomview_rev="" bl_gde_bomview_rev="" bl_item="#id7" bl_real_occurrence="" bl_revision="#id8" elemId="id61">
<GSIdentity elemId="id2" label="_RnrSUKuM1CaiD"/>
</BOMLine>
<DrawingSheet creation_date="2012-06-05T09:27:19Z" date_released="2012-06-05T09:25:33Z" ead_paragraph="" elemId="id69" format_used="BINARY" gov_classification="" highest_rev_prop="1" ip_classification="" keep_limit_prop="3" last_mod_date="2012-06-05T09:27:20Z" license_list="" object_desc="" object_name="dwg1_Sheet 1" owning_organization="">
<GSIdentity elemId="id24" label="RoL9sTu6BT4jNA"/>
</DrawingSheet>
<DrawingSheet creation_date="2012-06-05T09:28:44Z" date_released="2012-06-05T09:25:33Z" ead_paragraph="" elemId="id70" format_used="BINARY" gov_classification="" highest_rev_prop="1" ip_classification="" keep_limit_prop="3" last_mod_date="2012-06-05T09:28:45Z" license_list="" object_desc="" object_name="dwg3_Sheet 1" owning_organization="">
<GSIdentity elemId="id25" label="RoO9sTvgBT4jNA"/>
</DrawingSheet>
<DrawingSheet creation_date="2012-06-05T09:29:29Z" date_released="2012-06-05T09:25:33Z" ead_paragraph="" elemId="id71" format_used="BINARY" gov_classification="" highest_rev_prop="1" ip_classification="" keep_limit_prop="3" last_mod_date="2012-06-05T09:29:29Z" license_list="" object_desc="" object_name="dwg2_Sheet 1" owning_organization="">
<GSIdentity elemId="id26" label="RoO9sTfVBT4jNA"/>
</DrawingSheet>
<IMAN_Drawing elemId="id78" owning_site="#id4" primary_object="#id21" secondary_object="#id25" user_data="">
<GSIdentity elemId="id50" label="R8D9sTvgBT4jNA"/>
</IMAN_Drawing>
<IMAN_Drawing elemId="id79" owning_site="#id4" primary_object="#id22" secondary_object="#id26" user_data="">
<GSIdentity elemId="id56" label="R8D9sTfVBT4jNA"/>
</IMAN_Drawing>
<IMAN_Drawing elemId="id80" owning_site="#id4" primary_object="#id20" secondary_object="#id24" user_data="">
<GSIdentity elemId="id44" label="R8A9sTu6BT4jNA"/>
</IMAN_Drawing>
<UGPART creation_date="2012-06-05T09:25:30Z" date_released="2012-06-05T09:25:33Z" ead_paragraph="" elemId="id117" format_used="PART" gov_classification="" highest_rev_prop="1" ip_classification="" keep_limit_prop="3" last_mod_date="2012-06-05T09:25:34Z" license_list="" object_desc="dwg3" object_name="dwg3" owning_organization="">
<GSIdentity elemId="id21" label="RXM9sPifBT4jNA"/>
</UGPART>
<UGPART creation_date="2012-06-05T09:25:30Z" date_released="2012-06-05T09:25:33Z" ead_paragraph="" elemId="id118" format_used="PART" gov_classification="" highest_rev_prop="1" ip_classification="" keep_limit_prop="3" last_mod_date="2012-06-05T09:25:33Z" license_list="" object_desc="dwg1" object_name="dwg1" owning_organization="">
<GSIdentity elemId="id20" label="R3K9sPifBT4jNA"/>
</UGPART>
<UGPART creation_date="2012-06-05T09:25:28Z" date_released="2012-06-05T09:25:33Z" ead_paragraph="" elemId="id119" format_used="PART" gov_classification="" highest_rev_prop="1" ip_classification="" keep_limit_prop="3" last_mod_date="2012-06-05T09:25:34Z" license_list="" object_desc="dwg2" object_name="dwg2" owning_organization="">
<GSIdentity elemId="id22" label="xuO9sPifBT4jNA"/>
</UGPART>
</TCXML>
我正在寻找 xslt 1.0 解决方案。
这是我尝试使用的 xslt(我试图通过参数传递值来更新 UGPART 属性,但它是空值),但不知何故它不起作用。由于我无法更新 UGPART 的属性,因此我没有尝试更新我想要更新的绘图表名称。
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:plm="http://www.tcxml.org/Schemas/TCXMLSchema" version="1.0">
<xsl:output method="xml" indent="yes" omit-xml-declaration="yes"/>
<xsl:template match="/plm:TCXML/plm:IMAN_Drawing">
<xsl:copy>
<xsl:copy-of select="@*" />
<xsl:for-each select="/plm:TCXML/plm:IMAN_Drawing">
<xsl:variable name="currentSecObjectId" select="@secondary_object"/>
<xsl:variable name="RefSecObjectId" select="substring($currentSecObjectId,2)"/>
<xsl:variable name="currentPrimaryObjectId" select="/plm:TCXML/plm:IMAN_Drawing/@primary_object"/>
<xsl:variable name="RefPrimaryObjectId" select="substring($currentPrimaryObjectId,2)"/>
<xsl:call-template name="UGPart">
<xsl:with-param name="PriId" select="$RefPrimaryObjectId"/>
</xsl:call-template>
</xsl:for-each>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>
<xsl:template match="/plm:TCXML/plm:UGPART" name="UGPart">
<xsl:param name="PriId"/>
<xsl:copy>
<xsl:if test="@object_name="'Test'">
<xsl:attribute name="owning_organization">
<xsl:value-of select="$PriId"/>
</xsl:attribute>
</xsl:if>
<xsl:copy-of select="@*[not(name()='owning_organization')]" />
<xsl:apply-templates />
</xsl:copy>
</xsl:template>
提前致谢。