Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


RE: [xsl] A non self closed xsl:apply-templates element to create a text node for matching ...

From: "Michael Kay" <mike@------------>
To:
Date: 12/5/2006 3:41:00 AM
It's not legal to have an xsl:value-of element as a child of
xsl:apply-templates, and I'm really not sure what you would expect it to
mean.

I can't see the difficulty in having a single template rule that matches
both text nodes and attribute nodes, for example

<xsl:template match="text() | @*">

perhaps with appropriate filters and/or a special mode.

Michael Kay
http://www.saxonica.com/
 

> -----Original Message-----
> From: iwantto keepanon [mailto:iwanttokeepanon@xxxxxxxx] 
> Sent: 05 December 2006 03:08
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: [xsl] A non self closed xsl:apply-templates element 
> to create a text node for matching ...
> 
> 
> 
> 
> Using XSL 1.0 and xsltproc (Using libxml 20626, libxslt
> 10117 and libexslt 813).
> 
> I have a gallery XML file that I want to transform into an 
> Atom and a RSS feed.  The XML "setup" file contains relative 
> URLs.  I need a rule to transform text node and attribute 
> nodes to absolute URLs.  But coding 2 seperate templates is 
> kind of dumb.  So I tried to have the attribute rules (@*) 
> re-use the text (text()) rules.
> 
> The only problem is that I have never seen this approach and 
> I cannot find the syntax in the specs.  I have the shortest 
> XML and XSL code that represents what I am doing below.
> 
> And my question is, is this "legal".  Note the 
> "non-self-closed" apply-templates in the match="@*[...]".  I 
> guess I am creating a text node at runtime and matching that. 
>  I tried self::text() but, in attribute context, I dont think 
> that means anything.  Is there a better way to take attribute 
> text and match it into another rule?
> 
> (sorry if this is obtuse, hopefully the code helps) ...
> 
> 
> test.xml:
> <?xml version="1.0" encoding="utf-8"?>
> 
> <top>
>    <img src="../Russia2006/photos/img.jpg"/>
> </top>
> 
> 
> test.xsl:
> <?xml version="1.0" encoding="utf-8" standalone="yes"?> 
> <xsl:stylesheet version="1.0" 
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
> <xsl:output method="xml" version="1.0" omit-xml-declaration="no"
>    standalone="yes" encoding="utf-8" indent="yes" />
> 
> <xsl:template match="/">
>    <elem>
>       <xsl:apply-templates />
>    </elem>
> </xsl:template>
> 
> <xsl:template match="*">
>    <xsl:copy><xsl:apply-templates select="@*|node()" 
> /></xsl:copy> </xsl:template>
> 
> <xsl:template match="text()[ starts-with( ., '../Russia2006/' ) ]">
>    <xsl:text>http://site.com/gallery/Russia/2006/</xsl:text>
>    <xsl:value-of select="substring-after( ., '../Russia2006/' 
> )" /> </xsl:template>
> 
> <xsl:template match="@*">
>    <xsl:copy><xsl:value-of select="." /></xsl:copy> </xsl:template>
> 
> <!-- Match relative gallery image URLs only --> <xsl:template 
> match="@*[
>    ( self::src or self::href ) and
>    ( '' != substring-before( ., '.jpg' ) or ( '' != 
> substring-before( ., '.gif'
> ) ) ) ]">
> 
>    <xsl:attribute name="{local-name()}">
>       <!-- Tried, but does not work ... -->
>       <!-- xsl:apply-templates select="." / -->
>       <!-- xsl:apply-templates select="text()" / -->
>       <!-- xsl:apply-templates select="self::text()" / -->
> 
>       <!-- Does work ... creates a runtime text node? -->
>       <!-- Cross processor? -->
>       <xsl:apply-templates>
>          <xsl:value-of select="." />
>       </xsl:apply-templates>
>    </xsl:attribute>
> 
> </xsl:template>
> 
> </xsl:stylesheet>
> 
> 
> If this is really "leagle" and not just a "feature" of 
> xlstproc, then great!  If not, help please.
> 
> --
> Rodman


transparent
Print
Mail
Digg
delicious
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent