XSLT跳过一个节点

时间:2013-10-29 19:21:51

标签: xml xslt

我有一个以前曾经工作的xslt,但现在在转换期间“跳过”一个节点,我不明白为什么。接下来是xslt editi \ ed的一小部分可以使用。

  <?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2005/xpath-functions" exclude-result-prefixes="xs fn" xmlns:com="http://enrollmentservices.humana.com/V2.0/common" xmlns:ent="http://enrollmentservices.humana.com/V2.0/enrollmententities" xmlns:pro="http://enrollmentservices.humana.com/V2.0/product" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:pcext="http://enrollmentservices.humana.com/Policy/V2.0/PolicyExtract">
    <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
    <xsl:template match="/">
        <xsl:variable name="_PolicyPath" select="PolicyExtract/ContractLineOfCoverageList/ContractLineOfCoverage"/>
        <PolicyExtract>
            <xsl:copy-of select="pcext:TotalRecordCount"/>
            <ContractLineOfCoverageList>

            </ContractLineOfCoverageList>
        </PolicyExtract>
    </xsl:template>
</xsl:stylesheet> 

我想要的节点是当我通过它运行下面的文本时,它“跳过”该节点(并且只有那个节点)继承了适合通过提供的xslt的xml。

<?xml version="1.0" encoding="utf-8"?>
<PolicyExtract xmlns:ent="http://enrollmentservices.humana.com/V2.0/enrollmententities" xmlns:pcext="http://enrollmentservices.humana.com/Policy/V2.0/PolicyExtract" xmlns:pro="http://enrollmentservices.humana.com/V2.0/product" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><pcext:TotalRecordCount>4</pcext:TotalRecordCount><ContractLineOfCoverageList></ContractLineOfCoverageList></PolicyExtract>

计算TotalRecordCount,但不会转移。我也在调试器中尝试过它,它跳过了那一行。

任何想法?

1 个答案:

答案 0 :(得分:2)

从此更改您的xsl:copy-of声明:

<xsl:copy-of select="pcext:TotalRecordCount"/>

到此

<xsl:copy-of select="PolicyExtract/pcext:TotalRecordCount"/>

要复制pcext:TotalRecordCount元素:

<?xml version="1.0" encoding="UTF-8"?>
<PolicyExtract xmlns:com="http://enrollmentservices.humana.com/V2.0/common"
               xmlns:ent="http://enrollmentservices.humana.com/V2.0/enrollmententities"
               xmlns:pro="http://enrollmentservices.humana.com/V2.0/product"
               xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
               xmlns:pcext="http://enrollmentservices.humana.com/Policy/V2.0/PolicyExtract">
   <pcext:TotalRecordCount>4</pcext:TotalRecordCount>
   <ContractLineOfCoverageList/>
</PolicyExtract>