Subject: Re: [xsl] eliminating multiple repeated tags in my XML From: David Carlisle <davidc@xxxxxxxxx> Date: Mon, 10 Mar 2008 21:47:38 GMT |
You are making the templat ematch on related-article and then trying to group all the related-article children of this (related-artcicle) element, but there are none, so basically you just want to change to match article-meta instead. Also i changed your input example to be well formed and have some elements other than original-article types at this level just to show that these are not grouped, whereas the original articles are. I also removed the character map stuff as I didn't have it to hand at the right realtive location and they are not relevant to the problem (although actually they began life on this machine, if as I guess they are my map files you are using?) David <article><front><article-meta> [...other related-article siblings...] <related-article related-article-type="original-article"> <person-group person-group-type="author"> <name> <surname>Surname1</surname> <given-names>GivenName1</given-names> </name> </person-group> </related-article> <related-article related-article-type="original-article"> <person-group person-group-type="author"> <name> <surname>Surname2</surname> <given-names>GivenName2</given-names> </name> </person-group> </related-article> <related-article related-article-type="original-article"> <person-group person-group-type="author"> <name> <surname>Surname3</surname> <given-names>GivenName3</given-names> </name> </person-group> <article-title>Blah</article-title> <source>etc.</source> </related-article> <related-article>[...other related-article siblings...]</related-article> <foo/> </article-meta></front></article> <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"> <xsl:output method="xml" doctype-system="archivearticle.dtd" encoding="utf-8" indent="no" /> <xsl:template match="article-meta"> <xsl:copy> <xsl:copy-of select="@*"/> <xsl:for-each-group select="*" group-adjacent="exists(self::related-article[@related-article-type='original-article'])"> <xsl:choose> <xsl:when test="current-grouping-key()"> <related-article related-article-type="original-article"> <xsl:copy-of select="current-group()"/> </related-article> </xsl:when> <xsl:otherwise> <xsl:copy-of select="current-group()"/> </xsl:otherwise> </xsl:choose> </xsl:for-each-group> </xsl:copy> </xsl:template> <xsl:template match="@*|node()"> <xsl:copy copy-namespaces="no" inherit-namespaces="no"> <xsl:apply-templates select="@*|node()"/> </xsl:copy> </xsl:template> </xsl:stylesheet> $ saxon9 art.xml art.xsl <?xml version="1.0" encoding="utf-8"?> <!DOCTYPE article SYSTEM "archivearticle.dtd"> <article><front><article-meta><related-article related-article-type="original-article"><related-article related-article-type="original-article"> <person-group person-group-type="author"> <name> <surname>Surname1</surname> <given-names>GivenName1</given-names> </name> </person-group> </related-article><related-article related-article-type="original-article"> <person-group person-group-type="author"> <name> <surname>Surname2</surname> <given-names>GivenName2</given-names> </name> </person-group> </related-article><related-article related-article-type="original-article"> <person-group person-group-type="author"> <name> <surname>Surname3</surname> <given-names>GivenName3</given-names> </name> </person-group> <article-title>Blah</article-title> <source>etc.</source> </related-article></related-article><related-article>[...other related-article siblings...]</related-article><foo/></article-meta></front></article> ________________________________________________________________________ The Numerical Algorithms Group Ltd is a company registered in England and Wales with company number 1249803. The registered office is: Wilkinson House, Jordan Hill Road, Oxford OX2 8DR, United Kingdom. This e-mail has been scanned for all viruses by Star. The service is powered by MessageLabs. ________________________________________________________________________
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] eliminating multiple repe, Cindy Maisannes | Thread | RE: [xsl] eliminating multiple repe, Cindy Maisannes |
Re: [xsl] Error batch processing XM, Mark Peters | Date | [xsl] Easy question, big headache., Patrick Bergeron |
Month |