[XSL-LIST Mailing List Archive Home]
[By Thread]
[By Date]
David,
Thanks for the information it helped a lot. Just in case anyone else was interested and to close this thread this is what is working for me. Perhaps it could be a little more elegant but....... I have also included the source of channel-list.xml which is used earlier in the xslt
NB. This:
<xsl:copy-of select=".|following-sibling::table|following-sibling::subheading|following-sibling::para|following-sibling::images|following-sibling::top|following-sibling::list"/>
was the only way I could think of saying every following sibling except <notes>. Explicitly saying all the following-siblings I want except <notes>. I notice XSLT 2.0 has provision for this, anything better than what I have used?
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:variable name="contentnodes"/>
<xsl:template match="@xsi:noNamespaceSchemaLocation">
<xsl:attribute name="xsi:noNamespaceSchemaLocation">http://www.bath.ac.uk/bucs/system/xxeconfig/config/news/newseditor.xsd</xsl:attribute>
</xsl:template>
<xsl:template match="publish-to">
<xsl:copy>
<xsl:for-each select="document('channel-list.xml')/channels/area">
<xsl:variable name="attname">
<xsl:value-of select="."/>
</xsl:variable>
<xsl:choose>
<xsl:when test="$attname = //publish-to/*">
<xsl:attribute name="{$attname}"><xsl:text>true</xsl:text></xsl:attribute>
</xsl:when>
<xsl:otherwise>
<xsl:attribute name="{$attname}"><xsl:text>false</xsl:text></xsl:attribute>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</xsl:copy>
</xsl:template>
<xsl:template match="para[position() > 1]|table|subheading|images|top|list"/>
<xsl:template match="notes">
<xsl:copy>
<xsl:apply-templates select="child::*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="news-item/para[1]">
<content>
<xsl:copy-of select=".|following-sibling::table|following-sibling::subheading|following-sibling::para|following-sibling::images|following-sibling::top|following-sibling::list"/>
</content>
</xsl:template>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
--On 25 February 2005 12:27 +0000 David Carlisle <davidc@xxxxxxxxx> wrote:
Re: [xsl] grouping nodes inside a new parent node
Subject: Re: [xsl] grouping nodes inside a new parent node From: Andrew Male <ccsajm@xxxxxxxxxx> Date: Fri, 25 Feb 2005 15:25:23 +0000 |
David,
Thanks for the information it helped a lot. Just in case anyone else was interested and to close this thread this is what is working for me. Perhaps it could be a little more elegant but....... I have also included the source of channel-list.xml which is used earlier in the xslt
NB. This:
<xsl:copy-of select=".|following-sibling::table|following-sibling::subheading|following-sibling::para|following-sibling::images|following-sibling::top|following-sibling::list"/>
was the only way I could think of saying every following sibling except <notes>. Explicitly saying all the following-siblings I want except <notes>. I notice XSLT 2.0 has provision for this, anything better than what I have used?
Working XSLT ------------
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:variable name="contentnodes"/>
<xsl:template match="@xsi:noNamespaceSchemaLocation">
<xsl:attribute name="xsi:noNamespaceSchemaLocation">http://www.bath.ac.uk/bucs/system/xxeconfig/config/news/newseditor.xsd</xsl:attribute>
</xsl:template>
<xsl:template match="publish-to">
<xsl:copy>
<xsl:for-each select="document('channel-list.xml')/channels/area">
<xsl:variable name="attname">
<xsl:value-of select="."/>
</xsl:variable>
<xsl:choose>
<xsl:when test="$attname = //publish-to/*">
<xsl:attribute name="{$attname}"><xsl:text>true</xsl:text></xsl:attribute>
</xsl:when>
<xsl:otherwise>
<xsl:attribute name="{$attname}"><xsl:text>false</xsl:text></xsl:attribute>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</xsl:copy>
</xsl:template>
<xsl:template match="para[position() > 1]|table|subheading|images|top|list"/>
<xsl:template match="notes">
<xsl:copy>
<xsl:apply-templates select="child::*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="news-item/para[1]">
<content>
<xsl:copy-of select=".|following-sibling::table|following-sibling::subheading|following-sibling::para|following-sibling::images|following-sibling::top|following-sibling::list"/>
</content>
</xsl:template>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
channel-list.xml ----------------
<?xml version="1.0" encoding="UTF-8"?> <channels> <area>business</area> <area>international</area> <area>research</area> <area>swindon</area> <area>sport</area> <area>research</area> <area>releases</area> <area>community</area> <area>campus</area> </channels>
--On 25 February 2005 12:27 +0000 David Carlisle <davidc@xxxxxxxxx> wrote:
It depends a bit how general you want it to be but basically you want to have empty templates for all the elements that you want to group so the "identity" template doesn't copy them to the wrong place, then have a template for the first element in the group that copies all the group to where you want.
so if the rule is that the special nodes are para children of news-item that don't follow a table then you want
<xsl:template match="news-item/para[not(preceding-sibling::table)]"/>
then
<xsl:template match="news-item/para[1]" priority="10"> <content> <xsl:copy-of select=".|following-sibling::*para[not(preceding-sibling::table)]"/> </content>
as with any grouping problem you can probably speed it up with keys, although in this case I'd guess your news-items don't have hundreds of children so it might not make so much difference.
David
________________________________________________________________________ This e-mail has been scanned for all viruses by Star. The service is powered by MessageLabs. For more information on a proactive anti-virus service working around the clock, around the globe, visit: http://www.star.net.uk ________________________________________________________________________
------------------------------------------------- Andrew Male University of Bath Computing Services (BUCS) Ext: x4937 ccsajm@xxxxxxxxxx
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] grouping nodes inside a n, David Carlisle | Thread | Re: [xsl] grouping nodes inside a n, António Mota |
Re: [xsl] Using attributes and elem, António Mota | Date | Re: [xsl] Removing <?xml ... output, Emmanouil Batsis |
Month |
Keywords