xsl-list
[Top] [All Lists]

Re: [xsl] match="*:style"

2009-05-20 10:14:24
At 2009-05-20 15:34 +0200, Merico Raffaele wrote:
Dear Community

I process HTML/XHTML files passed as input to my XSLT stylesheet. I'm
working with SaxonB 9.1.0.2.
In order to catch the <style/> tag in the HTML/XHTML input file I defined
the following match-rule.

<xsl:template match="*:style[empty(./*) and normalize-space(./text()) eq
'']">

Your use of "./" is redundant in the above, and I'm not in the practice of addressing text() nodes directly. I would have used:

   [not(*) and not(normalize-space())]

Alternatively, if I wasn't worried about white-space, just [not(node())] would test for no child nodes of the element.

  <xsl:element name="{node-name(current())}"
namespace="{namespace-uri(current())}">

Use <xsl:copy/> to achieve the above.

    <xsl:apply-templates select="@*"/>
      <xslo:value-of select="' '"/>

Are you using namespace aliasing? It happens I use "xslo:" when I write stylesheets that write stylesheets. If so I suspect you want:

   <xslo:text><xsl:text> </xsl:text></xslo:text>

  </xsl:element>
</xsl:template>

Now I am surprised that above match applies also to style-attributes (i.e.
style="border: 1px solid red;").

It depends on how you are catching your attributes ... I see you are pushing them at your stylesheet:

    <xsl:apply-templates select="@*"/>

... but if you don't catch them, then their values will be added to the result tree as text.

I can imagine that this is caused by the star in the match.

No. That is explicitly for elements and not attributes because you have omitted the axis in the location path step.

I used the star to mask the namespace-prefix in order match style-tags in
the null and in the XHTML namespace (without prefix).

Sure.

Can anybody please explain me why this happens?

I suspect the built-in template rules are catching the attributes you are pushing at your stylesheet. But since you aren't showing more of your stylesheet it is difficult to tell what is happening with your style attributes because it might be another part of your stylesheet that is dealing with them.

If you just want to copy attributes, then you need something like this (untested):

<xsl:template match="*:style[not(*) and not(normalize-space())]">
  <xsl:copy>
    <xsl:copy-of select="@*"/>
    <xslo:text><xsl:text> </xsl:text></xslo:text>
  </xsl:copy>
</xsl:template>

... but I'm confused again because of your use of the "xslo:" prefix.

I hope this helps in some way.

. . . . . . . . . . . Ken

--
XSLT/XSL-FO/XQuery hands-on training - Los Angeles, USA 2009-06-08
Crane Softwrights Ltd.          http://www.CraneSoftwrights.com/s/
Training tools: Comprehensive interactive XSLT/XPath 1.0/2.0 video
Video lesson:    http://www.youtube.com/watch?v=PrNjJCh7Ppg&fmt=18
Video overview:  http://www.youtube.com/watch?v=VTiodiij6gE&fmt=18
G. Ken Holman                 mailto:gkholman(_at_)CraneSoftwrights(_dot_)com
Male Cancer Awareness Nov'07  http://www.CraneSoftwrights.com/s/bc
Legal business disclaimers:  http://www.CraneSoftwrights.com/legal


--~------------------------------------------------------------------
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>