cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Joerg Heinicke <>
Subject Re: Problem with xsl parsing xhtml
Date Thu, 16 Jan 2003 17:54:55 GMT
Hello Anna,

Anna Afonchenko wrote:
> Thank you very much Joerg, this worked!!!
> But now I have a more complex pattern, and it doesn't work again.
> I want to have a match that will say this:
> for each node, that has a child div node with class name test, copy to the
> output only the content of the div.
> So, for
> <p>
>     <div class="test">
>         <b>Text inside div</b>
>    </div>
> </p>
> the output should be
> <b>Text inside div</b>
> This is the template that I wrote:
> <xsl:template
> match="html:node()[child::node()[name()='div'][@class='test']]">
>    <xsl:apply-templates select="descendant::html:div/html:node()"/>
>  </xsl:template>

name() returns the namespace-prefix plus the element's name, e.g. 
"html:div". In the above code [name()='div'] won't be true, so the 
template does not match. One solution is to change it to 
[name()="html:div"], a second one to [local-name()="div"], but both are 
not really namespace aware. In my eyes the best solution is to use 

But the match can simplified:

<xsl:template match="html:*[html:div[@class='test']]">
   <xsl:apply-templates select="html:div/node()"/>

And if you want to remove <div class="test"/> in general, I think a template

<xsl:template match="html:div[@class='test']">
   <xsl:apply-templates select="node()"/>

is the best solution.



> This works (without html: namespace) if the input doesn't have xhtml doctype
> and xmlns.
> But when I put those, the output is not affected, i.e. the nodeset above is
> printed out as is.
> What am I doing wrong with namespaces this time?
> Thank you very very much for help.
> Anna.
> ----- Original Message -----
> From: "Joerg Heinicke" <>
> To: <>
> Sent: Thursday, January 16, 2003 7:18 PM
> Subject: Re: Problem with xsl parsing xhtml
> Hello Anna,
> all your elements in the XML are in the default namespace, so their
> complete name consists of the namespace-uri and the elment's name. If
> you want to match such an element, you must declare the namespace in the
> XSL. There is only one problem with default namespace: You can not
> simply declare it in the XSL, the matching won't work. You *must* bind
> it to a prefix. So changing your stylesheet to the following should
> solve your problem:
> <xsl:stylesheet version="1.0"
> xmlns:xsl=""
> xmlns:html="">
> <xsl:template match="node()|@*">
>    <xsl:copy>
>      <xsl:apply-templates select="node()|@*" />
>    </xsl:copy>
> </xsl:template>
> <xsl:template match="html:link[@rel='stylesheet']"/>
> </xsl:stylesheet>
> Regards,
> Joerg
> Anna Afonchenko wrote:
>>Hi all.
>>This is not really a Cocoon problem, but maybe you can help me with this.
>>I have the following XHTML page:
>><html xmlns="">
>><link href="pics/main_ns.css" rel="stylesheet" type="text/css" />
>>    <p>Some content</p>
>>and I want to parse it and take out the link to external stylesheet.
>>So I wrote the following xsl:
>><?xml version="1.0" encoding="UTF-8"?>
>><xsl:stylesheet version="1.0"
>><xsl:template match="node()|@*">
>><xsl:apply-templates select="node()|@*" />
>><xsl:template match="link[@rel='stylesheet']">
>>Here is my pipeline:
>><map:match pattern="parseXhtml">
>><map:generate src="test.html"/>
>><map:transform src="disableCSS.xsl"/>
>><map:serialize type="xml"/>
>>This stylesheet should output the original page without link tag that
>>links to external stylesheet.
>>The problem is, it doesn't match, e.g. the output is exactly the
>>original input with the link tag left.
>>If I take out the xhtml declaration from the input file, e.g. delete the
>>doctype declaration and xmlns attribute from the html tag, everything
>>works fine.
>>Is there any prorblem in Cocoon/xsl while matching files with xhtml
>>Can somebody explain this to me.
>>Sorry if this is a bit unrelated and thanks very much for help.

Please check that your question  has not already been answered in the
FAQ before posting.     <>

To unsubscribe, e-mail:     <>
For additional commands, e-mail:   <>

View raw message