Re: [xsl] Namespace and XPATH for XHTML transform

Subject: Re: [xsl] Namespace and XPATH for XHTML transform
From: Emmanouil Batsis <Emmanouil.Batsis@xxxxxxxxxxx>
Date: Mon, 16 May 2005 18:50:48 +0300
<xsl:value-of select="/xhtml:html/head/title"/>

should be

<xsl:value-of select="/xhtml:html/xhtml:head/xhtml:title"/>



Bret Parker wrote:

My task is to transform valid XHTML documents into slightly edited XHTML documents. Before I can achieve this, I must perfect the exercise of finding all the parts of my source documents. Eventually, I will be updating href attributes for certain anchor elements in hundreds of pages that need it. The stylesheet ancho.xsl is a simple exercise preparatory to that task.

The list archives has been immensely helpful. I am guessing this is an XPATH, namespace problem in the match="/" template.

In my stylesheet (complete stylesheet and source document, and output are
http://www.stockton.lib.ca.us/x/ancho.xsl http://www.stockton.lib.ca.us/subjects/geneal/genealogy-beginners.htm [source] http://www.stockton.lib.ca.us/x/gbeg3c.htm [output])


the transform does what I expect for the select="xhtml:html" template, but not for all of the match="/" template.

It is not returning the title of the document, nor is it returning the meta element attribute value of content (DC.date). The same XPATH expressions work fine, when I modify the source document and sidestep the namespace issues of dealing with XHTML. But editing all source documents is silly.

<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
		xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
		xmlns:xhtml="http://www.w3.org/1999/xhtml"; >
<xsl:strip-space  elements="*"/>

<xsl:template match="/">
        <xsl:variable name="myaccnt" select="count(//xhtml:a[.='My Account'])"/>

<html>
<head><title>Anchor Tags in :: <xsl:value-of select="/xhtml:html/head/title"/></title>
<link rel="stylesheet" href="/s/muns.css" title="default"/>
</head>
<body>
<h1>Anchor tags in :: <xsl:value-of select="/xhtml:html/head/title"/></h1>


<p>There are <xsl:text> </xsl:text><xsl:value-of select="$myaccnt"/> <xsl:text> </xsl:text><strong>My Account</strong><xsl:text> anchor tags in this document.</xsl:text></p>
<xsl:apply-templates />
<p><strong>Last rev. date:</strong> <xsl:text> </xsl:text><xsl:value-of select="/xhtml:html/head/meta[@name = 'DC.date']/@content" /></p>


</body>
</html>
</xsl:template>

<xsl:template match="xhtml:html">
<xsl:variable name="anchors" select="count(//xhtml:a)"/>
<p>There are <xsl:text> </xsl:text><xsl:value-of select="$anchors"/><xsl:text> anchor tags in this document.</xsl:text></p>



<xsl:apply-templates select="xhtml:body" />


</xsl:template>
... etc ...  [snip snip]

Bret Parker
Stockton-San Joaquin County Public Library
605 N. El Dorado St
Stockton, CA 95202

Have you used your electronic library subscription today?
 Pick a topic and read!   http://www.stockton.lib.ca.us/electronic/

Current Thread