xsl-list
[Top] [All Lists]

RE: [xsl] eliminating multiple repeated tags in my XML

2008-03-10 11:16:29
Hi David -- thanks for your help with this.  Unfortunately, it's still
not working for me.  There are other elements in my source at this
level, so I'm using the code that you first posted (with copy-of
substituted in for the original value-of).  My XML (with a bit more
context) looks like:

<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>
[...other related-article siblings...]
</article-meta> etc.


And my XSLT in its entirety at this point is stripped down to:


<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
version="2.0">

    <xsl:import href="../styles/iso8879/iso8879map.xsl"/>

    <xsl:output method="xml" doctype-system="archivearticle.dtd"
encoding="utf-8" indent="no" use-character-maps="iso8879"/>

    <xsl:template
 
match="/article/front/article-meta/related-article[(_at_)related-article-type
='original-article']">
        <related-article related-article-type="original-article">
         <xsl:for-each-group select="*"
group-adjacent="exists(self::related-article[(_at_)related-article-type='orig
inal-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>
        </related-article>
     </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>


...which continues to produce multiple <related-article>s.  When I run
the XSLT debugger in oXygen, I notice that it gets to the <xsl:choose>
and never matches on the <xsl:when>, only the <xsl:otherwise>.  I'm not
seeing what's wrong here, however.

Thanks again!


 
-----Original Message-----
From: David Carlisle [mailto:davidc(_at_)nag(_dot_)co(_dot_)uk] 
Sent: Friday, March 07, 2008 7:19 PM
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: Re: [xsl] eliminating multiple repeated tags in my XML


you've still not shown if there is anything other than these elements in
your source at this level. if so, use the code that I posted (except
replace value-of by copy-of since your related-article elements (now)
have structured content.

If on the other hand what you posted is all there is as the child of
some element, you don't need to group anything, just use
<related-article>
  <xsl:copy-of select="related-article/(@*,node())"/>
</related-article>


David



--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--