Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

understanding "xsl:apply-templates"

46 views
Skip to first unread message

fo...@citizen14.de

unread,
Jan 2, 2013, 2:33:13 AM1/2/13
to
Hello,
I am new to xml/xsl and I try to understand xsl:apply-templates. I have some example files (see bottom). I thought that I would at least get an output "bla" or "some text", but the result is a blank page. I thought that xsl:apply-templates returns the inner xml specified in the select option, but it looks like I am wrong and I need your help.

Thanks

warehouse.xml

<?xml version="1.0" encoding="utf-8" ?>
<?xml-stylesheet type="text/xsl" href="warehouse.xsl"?>
<warehouse>
<container>
some text
<item>
<name>book</name>
<value>1.23</value>
</item>
<item>
<name>phone</name>
<value>45.6</value>
</item>
</container>
</warehouse>

and warehouse.xsl

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="text"/>

<xsl:template match="/">
<xsl:apply-templates select="container" />"
</xsl:template>

<xsl:template match="container">
bla
</xsl:template>

</xsl:stylesheet>

Bjoern Hoehrmann

unread,
Jan 2, 2013, 7:09:18 AM1/2/13
to
* fo...@citizen14.de wrote in microsoft.public.xsl:
>I am new to xml/xsl and I try to understand xsl:apply-templates. I have
>some example files (see bottom). I thought that I would at least get an
>output "bla" or "some text", but the result is a blank page. I thought
>that xsl:apply-templates returns the inner xml specified in the select
>option, but it looks like I am wrong and I need your help.

No, xsl:apply-templates lets the processor apply applicable templates.

>warehouse.xml
>
><?xml version="1.0" encoding="utf-8" ?>
><?xml-stylesheet type="text/xsl" href="warehouse.xsl"?>
><warehouse>
> <container>
>[...]

> <xsl:template match="/">
> <xsl:apply-templates select="container" />"
> </xsl:template>
>
> <xsl:template match="container">
> bla
> </xsl:template>

In the first template, '/' and 'container' make '/container', but the
document element in your document is 'warehouse'. You would have to use
xsl:apply-templates on 'warehouse/container' to make the second template
apply, or make the first template match on 'warehouse'.
--
Björn Höhrmann · mailto:bjo...@hoehrmann.de · http://bjoern.hoehrmann.de
Am Badedeich 7 · Telefon: +49(0)160/4415681 · http://www.bjoernsworld.de
25899 Dagebüll · PGP Pub. KeyID: 0xA4357E78 · http://www.websitedev.de/
0 new messages