Subject: Re: [xsl] where's here the error From: Matthieu Ricaud-Dussarget <matthieu.ricaud@xxxxxxxxx> Date: Mon, 02 Jan 2012 11:17:21 +0100 |
frontpage-article.xsl :
<?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="section/entry"> <h2><value-of select="title" /></h2> </xsl:template>
<xsl:template match="*"> <xsl:apply-templates/> </xsl:template>
<xsl:template match="text()"> <xsl:value-of select="."/> </xsl:template>
<?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/"> <xsl:apply-templates select="data/recent-posts/section/entry | data/section/section/entry"/> <!-- I ignore image/section cause there is no title element here--> </xsl:template>
<xsl:template match="section/entry"> <h2><value-of select="title" /></h2> </xsl:template>
<?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/"> <xsl:apply-templates /> </xsl:template>
<xsl:template match="*"> <xsl:apply-templates /> </xsl:template>
<xsl:template match="text()"> <!-- don't ouput text nodes--> </xsl:template>
<xsl:template match="section/entry"> <h2><value-of select="title" /></h2> </xsl:template>
The first 2 templates can be ommited because they do the same as the default xslt templates, but it makes it clear what's happen : - when you encounter the root element, don't ouput anything, see what's happen inside - when you encounter any element, don't ouput anything, see what's happen inside - when you encounter any text node just don't ouput anything - when you encounter section/entry, forget the 2nd template and display the title.
You can do the same more simple : <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="section/entry"> <h2><value-of select="title" /></h2> </xsl:template>
The problem with this generic solution is that if there is no title element (as this is the case for image/section/entry), you will get an empty h2 element. You can add a test here or just deal with the first solution.
Regards, Matthieu
-- Matthieu Ricaud IGS-CP Service Livre numC)rique
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Path according to a child, Martin Honnen | Thread | Re: [xsl] where's here the error, graham.heath |
Re: [xsl] Path according to a child, Gian Paolo Bernardin | Date | Re: [xsl] Path according to a child, Martin Honnen |
Month |