xsl:copy-of不输出元素,而是输出元素

时间:2012-07-26 17:12:08

标签: xml xslt

以下XSLT xsl:copy-of的输出是什么(我正在使用oXigen):

     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>    

1 个答案:

答案 0 :(得分:2)

您已设置output method="text",因此输出是结果树中任何文本节点的序列化。请改用output method="xml"