【问题标题】:XSLT on XML Get parent Value from a mixed NodeXSLT on XML 从混合节点获取父值
【发布时间】:2019-07-19 02:01:17
【问题描述】:

我有一个包含一些混合节点的 XML,我只想获取父节点的值,而不是子节点的值。

我的 XML

<?xml version="1.0" encoding="UTF-8"?>
<Records>
   <DET>
      <detnumber>100126</detnumber>
      <EmployeeNo>100126</EmployeeNo>
      <action>CHANGE</action>
      <first_name> NewHire-4th
                        <previous>NewHire</previous>
                     </first_name>
      <last_name>Test-Changed 4th
                        <previous>Test-Changed 3rd</previous>
                     </last_name>
      <birth_name>
                        NewHire-Changed 4th
                        <previous>NewHire-Changed 3rd</previous>
                     </birth_name>
      <formal_name>
                        NewHire-4th Test-Changed 4th
                        <previous>NewHire Test-Changed 3rd</previous>
                     </formal_name>
      <salutation>
                        MISS
                        <previous>MRS</previous>
                     </salutation>
      <email_address>
                        testHire4@gmail.com
                        <previous>testHire2@gmail.com</previous>
                     </email_address>
   </DET>
</Records>

使用 XSLT 2.0,

我主要在我的 xslt 中使用副本,但正在复制整个节点及其子节点。我需要能够仅限于父母。

<xsl:copy-of select="first_name"/>
<xsl:copy-of select="last_name"/>
<xsl:copy-of select="birth_name"/>
<xsl:copy-of select="formal_name"/>
<xsl:copy-of select="salutation"/>

以下是我的首选输出

<?xml version="1.0" encoding="UTF-8"?>
<Records>
   <DET>
      <detnumber>100126</detnumber>
      <EmployeeNo>100126</EmployeeNo>
      <action>CHANGE</action>
      <first_name> NewHire-4th</first_name>
      <last_name>Test-Changed 4th</last_name>
      <birth_name>NewHire-Changed 4th</birth_name>
      <formal_name>NewHire-4th Test-Changed 4th</formal_name>
      <salutation>MISS</salutation>
      <email_address>testHire4@gmail.com</email_address>
   </DET>
</Records>

【问题讨论】:

    标签: xslt-2.0


    【解决方案1】:
    Check this Code:-
    
    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="html" indent="yes"/>
    
    <xsl:template match="@*|node()">
        <xsl:copy>
            <xsl:apply-templates select="@*|node()"/>
        </xsl:copy>
    </xsl:template>
    
        <xsl:template match="previous"/>
    </xsl:stylesheet>
    
    猜你喜欢
    • 2012-05-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多