Skip to main content

By clicking Submit, you agree to the developerWorks terms of use.

The first time you sign into developerWorks, a profile is created for you. Select information in your developerWorks profile is displayed to the public, but you may edit the information at any time. Your first name, last name (unless you choose to hide them), and display name will accompany the content that you post.

All information submitted is secure.

  • Close [x]

The first time you sign in to developerWorks, a profile is created for you, so you need to choose a display name. Your display name accompanies the content you post on developerworks.

Please choose a display name between 3-31 characters. Your display name must be unique in the developerWorks community and should not be your email address for privacy reasons.

By clicking Submit, you agree to the developerWorks terms of use.

All information submitted is secure.

  • Close [x]

Importing text as XML with XI

What about real-life data?

Return to article.


Listing 4. The last step is a style sheet
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:an="http://ananas.org/2002/sample">

<xsl:template match="an:address-book">
   <sect1><xsl:apply-templates/></sect1>
</xsl:template>

<xsl:template match="an:alias">
   <address>
      <xsl:variable name="id" select="an:id"/>
      <xsl:for-each select="/an:address-book/an:note[an:id = $id]">
         <personname><xsl:value-of select="an:fields/an:field[an:key='name']/an:value"/></personname>
         <xsl:if test="an:fields/an:field[an:key='country']/an:value">
            <street><xsl:value-of select="an:fields/an:field[an:key='address']/an:value"/></street>
            <postcode><xsl:value-of select="an:fields/an:field[an:key='zip']/an:value"/></postcode>
            <city><xsl:value-of select="an:fields/an:field[an:key='city']/an:value"/></city>
            <state><xsl:value-of select="an:fields/an:field[an:key='state']/an:value"/></state>
            <country><xsl:value-of select="an:fields/an:field[an:key='country']/an:value"/></country>
         </xsl:if>
      </xsl:for-each>
      <email><xsl:value-of select="an:email"/></email>
   </address>
</xsl:template>

<xsl:template match="an:note"/>

</xsl:stylesheet>

Return to article.