xsl-list
[Top] [All Lists]

Re: Retrieving urls when using document()

2005-11-17 00:35:26
Hi Lynn,

What you can do is to pass the file name as a parameter when you call apply templates. Something like below should work (the changes are in lines after comments):

<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
    <xsl:output method="html" encoding="iso-8859-1"/>

<xsl:variable name="documents" select="document(/documents/doc/@href)"/> <!-- Keep the document element from the initial document in a variable -->
    <xsl:variable name="root" select="/documents"/>
    <xsl:template match="/">
        <xsl:for-each select="$documents">
            <xsl:apply-templates>
                <!-- Pass the file name as a parameter -->
<xsl:with-param name="name" select="$root/doc[position()]/@href"/>
            </xsl:apply-templates>
        </xsl:for-each>
    </xsl:template>

    <xsl:template match="Title|Table/Title">
        <!-- The file name as a parameter -->
        <xsl:param name="name" select="''"/>
        <p>
            <a>
                <!-- Use the name parameter -->
<xsl:attribute name="href"><xsl:value-of select="substring-before($name,'.xml')"/>.html#<xsl:value-of select="."/></xsl:attribute>
                <xsl:value-of select="."/>
            </a>
        </p>
    </xsl:template>

</xsl:stylesheet>

Best Regards,
George
---------------------------------------------------------------------
George Cristian Bina
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com


Lynn Alford wrote:
I'm trying to create a nice table of contents from multiple XML files. Cruising through the FAQ, I ran across the idea of using

filelist.xml

<documents>
  <doc href="105_imp.xml"/>
  <doc href="110_vc.xml"/>
  <doc href="115_his.xml"/>
</documents>

table_of_contents.xsl

<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
  <xsl:output method="html" encoding="iso-8859-1"/>

  <xsl:variable name="documents" select="document(/documents/doc/@href)"/>

<xsl:template match="/">
  <xsl:for-each select="$documents">
        <xsl:apply-templates />
    </xsl:for-each>
</xsl:template>

 <xsl:template match="Title|Table/Title">
    <p>

           <a>
<xsl:attribute name="href"><xsl:value-of select="substring-before(name($documents),'.xml')"/>.html#<xsl:value-of select="."/></xsl:attribute>
                     <xsl:value-of select="."/>
         </a>
    </p>
  </xsl:template>

</xsl:stylesheet>

Current output fragment

<p><a href=".html#About">About</a></p>
<p><a href=".html#Message">Message</a></p>


So this is really close to doing what I hope for but I'd like to find out if it is possible to get

<xsl:value-of select="substring-before($documents,'.xml')"/>

to reliably give me the href of the document that I'm processing in the for-each loop. Doesn't look like it should be difficult but it is stumping me.

Lynn


Lynn Alford                             Tel     (07) 47 81 6256
ITR                                             Email:  
imla(_at_)jcu(_dot_)edu(_dot_)au
JCU QLD 4811 Australia                  ICQ: 64096907
MSN: nicarra60(_at_)hotmail(_dot_)com              Y!: nicarra60

'I think an "uncatched exception" deserves three bug reports: one for the
exception, one for not catching it, and one for abuse of the English
language.'  Michael Kay





--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



<Prev in Thread] Current Thread [Next in Thread>