0

以下 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>    
4

1 回答 1

2

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

于 2012-07-26T17:29:06.317 回答