You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何扩展现有XSLT实现XML属性忽略与<Name>节点属性新增

Here's the extended XSLT that meets all your requirements, building on your existing code:

<?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"/>

<!-- Identity template: copies all nodes/attributes by default -->
<xsl:template match="@* | node()">
  <xsl:copy>
    <xsl:apply-templates select="@* | node()"/>
  </xsl:copy>
</xsl:template>

<!-- 1. Ignore Classification's ParentID attribute -->
<xsl:template match="Classification/@ParentID"/>

<!-- 2. Ignore STEP-ProductInformation's WorkspaceID attribute -->
<xsl:template match="STEP-ProductInformation/@WorkspaceID"/>

<!-- Keep existing rule: suppress Name nodes with ContextID='de_DE' -->
<xsl:template match="Name[@ContextID='de_DE']"/>

<!-- 3. Add Translation_Status="UpToDate" to non-suppressed Name nodes -->
<xsl:template match="Name[not(@ContextID='de_DE')]">
  <xsl:copy>
    <xsl:attribute name="Translation_Status">UpToDate</xsl:attribute>
    <xsl:apply-templates select="@* | node()"/>
  </xsl:copy>
</xsl:template>

<!-- Keep existing rule: suppress Value nodes with ContextID='de_DE' -->
<xsl:template match="Value[@ContextID='de_DE']"/>

</xsl:stylesheet>

Key changes explained:

  • Ignoring specific attributes: We added two targeted templates that match the exact attributes you want to exclude. Since these templates have no content, those attributes won't be copied to the output.
  • Adding the Translation_Status attribute: We created a template for Name nodes that aren't suppressed (i.e., those without ContextID='de_DE'). This template copies the original node, adds the new attribute first, then preserves all existing attributes and child content of the Name node.

When applied to your sample XML, the output will:

  • Omit the ParentID from the Classification node
  • Omit the WorkspaceID from the root STEP-ProductInformation node
  • Add Translation_Status="UpToDate" to the remaining Name node (the one with ContextID='fr_FR')
  • Keep suppressing the de_DE Name and Value nodes as before

内容的提问来源于stack exchange,提问作者user9020437

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 04:54:07