[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: mapping attributes.

Subject: Re: mapping attributes.
From: "jackson" <jackson@xxxxxxxxxxx>
Date: Tue, 7 Nov 2000 11:33:57 +1000
mapping attributes in xsl
Jamie

I wrote a DTD for your example (necessary because you
want to use IDs and IDREFs). I renamed the attribute
ID of RELATED to IDREF, in line with what it is.

I also renamed one of the ID/IDREFs in your example.
It was needed.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE DOCUMENT [
<!ELEMENT DOCUMENT (SECTION*)>
<!ELEMENT SECTION (TITLE, BODY, RELATED*)>
<!ATTLIST SECTION
          ID       ID    #IMPLIED
>
<!ELEMENT TITLE (#PCDATA)>
<!ELEMENT BODY (#PCDATA)>
<!ELEMENT RELATED (#PCDATA)>
<!ATTLIST RELATED
          IDREF    IDREF    #REQUIRED
>
]>

<DOCUMENT>
   <SECTION ID="SOME_ID">
       <TITLE>This sections title</TITLE>
       <BODY />
       <RELATED IDREF="ANOTHER_ID" />   
   </SECTION>   

   <SECTION ID="ANOTHER_ID">
       <TITLE>Another sections title</TITLE>
       <BODY />
       <RELATED IDREF="SOME_ID" />
   </SECTION>   
</DOCUMENT>


This style sheet does what i think you want. If you run this
over the HTML above you'll need to put some content into
the first section, or (as i did) doctor the HTML file with a
bunch of <BR>s before the second section. This way you'll
get to see the links in action.

<?xml version="1.0"?>

<xsl:stylesheet version="1.0"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns="http://www.w3.org/TR/REC-html40">

  <!-- ====================================
       Output method.
       ==================================== -->
  <xsl:output method="html"/>

  <!-- =====================================
       Root template
       ===================================== -->
  <xsl:template match="/">
    <HTML>
      <HEAD>
        <META http-equiv="Content-Type"
              content="text/html; charset=iso-8859-1"/>
        <META http-equiv="Expires" content="0"/>
      </HEAD>
      <BODY>
        <xsl:apply-templates/>
      </BODY>
    </HTML>
  </xsl:template>

  <xsl:template match="DOCUMENT">
    <xsl:apply-templates/>
  </xsl:template>

  <xsl:template match="SECTION">
    <!-- Add HTML link anchor. Referred to by RELATED -->
    <A>
      <xsl:attribute name="name">
        <xsl:value-of select="@ID"/>
      </xsl:attribute>
    </A>

    <xsl:apply-templates/>
  </xsl:template>

  <xsl:template match="TITLE">
    <H2><xsl:apply-templates/></H2>
  </xsl:template>

  <xsl:template match="RELATED">
    <!-- Write out IDREF. -->
    IDREF: <xsl:value-of select="@IDREF"/>

    <BR/> <!-- Just for layout. -->

    <!-- Write out title of section referred to. -->
    <xsl:for-each select="id(@IDREF)">
      Title of section referred to: <xsl:value-of select="TITLE"/>
    </xsl:for-each>

    <BR/> <!-- Just for layout. -->

    <!-- Add HTML link to section. -->
    See also:
    <A>
      <xsl:attribute name="href">
        <xsl:text>#</xsl:text><xsl:value-of select="@IDREF"/>
      </xsl:attribute>

      <!-- Link text here. Section title is OK. -->
      <xsl:value-of select="id(@IDREF)/TITLE"/>
    </A>
  </xsl:template>

</xsl:stylesheet>


David Jackson



 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.