2012-07-26 53 views
0

WHI難道是以下XSLT的xsl:copy-of輸出是這(我使用oXigen):XSL:複製的不輸出的元素,但它們的內容

 Spot 1 HappinessUnit 
    Spot 2 HappinessUnit 
      Spot Begin:----------- 

1 

    317981023 
    THIRD PERSON 
    1 
    SMITH, ROBERT 
    123 Coglan ST 
    (613) 123-1234 
    OTTAWA, ONT 

    AFJALGJH12348 
    ONT 
    M 
      Spot End:----------- 

我期待這樣的事情:

<Driver> 
    <ID_Num>317981023</ID_Num> 
    <RoleTrans>THIRD PERSON</RoleTrans> 
    <RoleNumber>1</RoleNumber> 
    <PersonNameText>SMITH, ROBERT</PersonNameText> 
    <AddressFullText>123 Coglan ST</AddressFullText> 
    <PersonalTelephoneNumber>(613) 123-1234</PersonalTelephoneNumber> 
    <CityProvince>OTTAWA, ONT</CityProvince> 
    <PostalZipcode/> 
    <Licence>AFJALGJH12348</Licence> 
    <ProvinceOfIssue>ONT</ProvinceOfIssue> 
    <Sex>M</Sex> 
</Driver> 

這是代碼:

<xsl:stylesheet version="2.0" 
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 


    <xsl:output method="text" /> 
    <xsl:variable name="in" select="/"/> 
    <xsl:variable name="filter" select="document('elementsToBeFilterOut.xml')"/> 

    <xsl:template match="/"> 
     <xsl:apply-templates select="*"> 
      <xsl:with-param name="f" select="$filter/*"/> 
     </xsl:apply-templates> 
    </xsl:template> 

    <xsl:template match="*"> 
     <xsl:param name="f"/> 
     <xsl:choose> 
      <xsl:when test="$f/*"> 
     Spot 1 <xsl:value-of select="$f/*/name()" /> 
     Spot 2 <xsl:value-of select="*[name() = '/agency/HappinessUnit/location']/name()" /> 
       <xsl:for-each select="*[name() = $f/*/name()]"> 
        <xsl:value-of select="current()/name()" /> 
        <xsl:apply-templates select="."> 
         <xsl:with-param name="f" select="f/*[name() = current()/name()]"/> 
        </xsl:apply-templates> 
       </xsl:for-each> 

      </xsl:when> 
      <xsl:otherwise> 
       Spot Begin:----------- 
       <xsl:copy-of select="."/> 
       Spot End:----------- 
      </xsl:otherwise> 
     </xsl:choose> 
Spot 3 
    </xsl:template> 

</xsl:stylesheet>  

回答

2

你有output method="text"一套所以輸出結果樹中任何文本節點的序列化。改爲使用output method="xml"

+0

非常感謝。我沒有意識到這會產生這種影響。非常感謝。這解決了它。 – 2012-07-26 19:37:32

相關問題