Re: [xsl] display parts of XML tree with xsl:copy ?

Subject: Re: [xsl] display parts of XML tree with xsl:copy ?
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Tue, 26 Feb 2002 15:43:36 +0000
Hi Robert,

> How can I controll that only those ancestors are copied that are in
> an valid articles supertree?

Using the push method (the identity template plus other templates to
steer the processing), you need to add a template that matches the
document element of your stylesheet (which I'll assume is called
'issues'), and tells the processor to only process those issue
elements that contain an article with an author named 'Karen Botnich':

<xsl:template match="issues">
  <issues>
    <xsl:apply-templates select="issue[articles/article/authors/author =
                                       'Karen Botnich']" />
  </issues>
</xsl:template>

Using the pull method (the single template with the xsl:for-each) you
do roughly the same thing - just select those issues for processing:

<xsl:template match="/">
  <issues>
    <xsl:for-each
      select="/issues/issue[articles/article/authors/author =
                            'Karen Botnich']">
      <issue>
        <xsl:copy-of select="volume | number" />
        <articles>
          <xsl:copy-of
            select="articles/article[authors/author = 'Karen Botnich']" />
        </articles>
      </issue>
    </xsl:for-each>
  </issues>
</xsl:template>

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread