Re: A general pattern match

Subject: Re: A general pattern match
From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx>
Date: Mon, 18 Jan 1999 15:49:28 -0500
At 99/01/18 16:19 +0000, Nic Williams wrote:
>I'm looking for a way to set a general match
>for anything that isn't already included in my XSL stylesheet. Any element
>matched by this general statement should then be returned including it's
>attributes.

This can be done with <xsl:copy>, illustrated below with XT.

>For example I would like the following XML statement returned as an exact
>copy assuming there is no statement matching on 'person'.
>
><person age="28" weight="93">Nic Williams</person>

I've incorporated that markup in the example below.

Note how I've used a priority on the fall-back <xsl:template> so there
won't be any conflict with explicit rules (which wouldn't be reported by XT
but is allowed to be reported as an error by an XSL processor).

Note also that the code below will copy *everything* in the element, not
just its text and attributes ... it will also copy comments and processing
instructions because if comments and processing instructions are not
separately matched, the fall-back code below will copy those as well.

I hope this helps.

.......... Ken

T:\copyex>type test.xml
<?xml version="1.0"?>
<doc>
<other>Some information 1</other>
<person age="28" weight="93">Nic Williams</person>
<other>Some information 2</other>
</doc>
T:\copyex>type test.xsl
<xsl:stylesheet
       xmlns:xsl="http://www.w3.org/TR/WD-xsl";
       result-ns="">

<xsl:template match="*|comment()|pi()|@*" priority="-1">
  <xsl:copy>
    <xsl:apply-templates select="*|text()|comment()|pi()|@*"/>
  </xsl:copy>
</xsl:template>

<xsl:template match="other">
  <p>Other: <xsl:apply-templates/></p>
</xsl:template>

</xsl:stylesheet>
T:\copyex>call xsl test.xml test.xsl test.out
T:\copyex>type test.out
<doc>
<p>Other: Some information 1</p>
<person age="28" weight="93">Nic Williams</person>
<p>Other: Some information 2</p>
</doc>
T:\copyex>



--
G. Ken Holman         mailto:gkholman@xxxxxxxxxxxxxxxxxxxx
Crane Softwrights Ltd.  http://www.CraneSoftwrights.com/s/
Box 266,                                V: +1(613)489-0999
Kars, Ontario CANADA K0A-2E0            F: +1(613)489-0995
Training:   http://www.CraneSoftwrights.com/s/schedule.htm
Resources: http://www.CraneSoftwrights.com/s/resources.htm
Shareware: http://www.CraneSoftwrights.com/s/shareware.htm
Next XSL Training (see training link):   WWW8 - 1999-05-11


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


Current Thread