This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: mapping attributes.
- To: <xsl-list at mulberrytech dot com>
- Subject: Re: mapping attributes.
- From: "jackson" <jackson at dstc dot edu dot au>
- Date: Tue, 7 Nov 2000 11:33:57 +1000
- Organization: DSTC
- References: <20001106151238.A18479@lecart.com>
- Reply-To: xsl-list at mulberrytech dot com
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