XSLT在特定的节点组上工作 我想要一个XPath,它将考虑一个特定的组,忽略所有其他组。下面是我的XML代码: <GetBillList> <Case> <CaseID>...</CaseID> <BillGroup> <BillGroupID>...</BillGroupID> </BillGroup> </Case> <StartDate>2014-01-01</StartDate> <GetBillListResponse> <Bill> <BillStatusCode> <BillStatusCode>type description</BillStatusCode> <typecode>1</typecode> </BillStatusCode> <EBillProcessStatusCode> <EBillProcessStatusCode>type description</EBillProcessStatusCode> <typecode>2</typecode> </EBillProcessStatusCode> <ToDate>...</ToDate> </Bill> </GetBillListResponse> </GetBillList> ... ... 2014-01-01 类型说明 1. 类型说明 2. ...

XSLT在特定的节点组上工作 我想要一个XPath,它将考虑一个特定的组,忽略所有其他组。下面是我的XML代码: <GetBillList> <Case> <CaseID>...</CaseID> <BillGroup> <BillGroupID>...</BillGroupID> </BillGroup> </Case> <StartDate>2014-01-01</StartDate> <GetBillListResponse> <Bill> <BillStatusCode> <BillStatusCode>type description</BillStatusCode> <typecode>1</typecode> </BillStatusCode> <EBillProcessStatusCode> <EBillProcessStatusCode>type description</EBillProcessStatusCode> <typecode>2</typecode> </EBillProcessStatusCode> <ToDate>...</ToDate> </Bill> </GetBillListResponse> </GetBillList> ... ... 2014-01-01 类型说明 1. 类型说明 2. ...,xml,xslt,xpath,Xml,Xslt,Xpath,XSLT代码: <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/> <xsl:strip-space elements="*"/> <xsl:template

XSLT代码:

     <xsl:stylesheet version="1.0" 
     xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
    <xsl:strip-space elements="*"/>

    <xsl:template match="*">
    <xsl:copy>
    <xsl:for-each select="id | typecode">
    <xsl:attribute name="{name()}">
    <xsl:value-of select="."/>
    </xsl:attribute>
    </xsl:for-each>
    <xsl:apply-templates select="node()[not(self::id or self::typecode)]"/>
    </xsl:copy>
    </xsl:template>

    <xsl:template match="*[name(.) = name(..)]">
    <xsl:apply-templates/>
    </xsl:template>
    </xsl:stylesheet>

我希望它只在“GetBillListResponse”上工作,而忽略“Case”组和“StartDate”元素

期望输出:

    <GetBillList>
    <GetBillListResponse>
    <Bill>
    <BillStatusCode typecode="1">type description</BillStatusCode>
    <EBillProcessStatusCode typecode="2">type description</EBillProcessStatusCode>
    <ToDate>...</ToDate>
    </Bill>
    </GetBillListResponse>
    </GetBillList>

类型说明
类型说明
...

非常感谢您在这方面的帮助

如果我的答案基于您当前的输入和XSLT,只需添加:

<xsl:template match="Case|StartDate"/>

在样式表中

编辑

如果要在喜欢的节点上工作,请改为:

<xsl:template match="/">
    <GetBillList>
        <xsl:apply-templates select="GetBillList/GetBillListResponse"/>
    </GetBillList>
</xsl:template>


你好,Joel,谢谢你的回复。您的代码正在提供所需的输出,但是是否可以提供我们想要工作的节点,而不是我们想要忽略的节点?很好。谢谢你的帮助。我用了一种错误的方式来尝试。非常感谢。