[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: mapping attributes.
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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|