[xsl] Extracting XPath stuff for an href.

Subject: [xsl] Extracting XPath stuff for an href.
From: James Steward <jamessteward@xxxxxxxxxxxxxxx>
Date: Mon, 03 Jul 2006 08:32:17 +1000
Hi All,

Being a newbie to XSL I'm probably going to ask some dumb questions but
I have googled for what I'm trying to do and tried many variations to
this and not yet found a solution.

I have a test.dtd with basic structure as...

<?xml version="1.0" encoding="UTF-8"?>
<!ELEMENT AAA (BBB,CCC)>
<!ELEMENT BBB (DDD+)>
<!ELEMENT CCC (DDD+)>
<!ELEMENT DDD EMPTY>
<!ATTLIST DDD
	eee CDATA #REQUIRED>

And an test.xml doc that looks like...

?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="test.xsl"?>
<!DOCTYPE AAA SYSTEM "test.dtd">
<AAA>
        <BBB>
                <DDD eee="Bar1"/>
		...etc
	</BBB>
        <CCC>
                <DDD eee="BarX"/>
		...etc
	</CCC>
</AAA>

Then my xsl looks like,
<?xml version="1.0"?><!--test.xsl-->
<!--XSLT 1.0 - http://localhost -->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
version="1.0">

       <xsl:template match="/">
                <html>
                        <head><title>Test</title></head>
                        <body>
                        <h1>
                                <center>
                                        <xsl:text>Test</xsl:text>
                                        <hr/>
                                </center>
                        </h1>
                                <xsl:apply-templates/>
                        </body>
                </html>
        </xsl:template>	

        <xsl:template match="BBB">
                <p/><b><i><u><xsl:text>BBB</xsl:text></u></i></b>
                <xsl:apply-templates select="//DDD"/>
        </xsl:template>

        <xsl:template match="CCC">
                <p/><b><i><u><xsl:text>CCC</xsl:text></u></i></b>
                <xsl:apply-templates select="//DDD"/>
        </xsl:template>

	<xsl:template match="//DDD">
		<p/><u>
		<a href="cgi-bin/test.sh?{@eee},{parent::node()}"
		target="_blank">DDD <xsl:value-of select="@eee"/>
		</a></u>
	</xsl:template>
</xsl:stylesheet>

Now what I'm hoping for in the output is something like;

<a href="cgi-bin/test.sh?Bar1,BBB" target="_blank">DDD Bar1</a>

But all I get is;

<a href="cgi-bin/test.sh?Bar1, " target="_blank">DDD Bar1</a>

So the @eee works, but there's something wrong with the use of XPath
parent::node() ?

I'd be grateful if someone could give me a prod in the right direction.

Oh, I'm just running thttpd with files in my /var/www dir and using
Mozilla Firefox pointed at http://localhost for testing.

Regards,
James.

Current Thread