xsl-list
[Top] [All Lists]

Re: [xsl] Why can a template rule match on a child of multiple elements but cannot match on multiple children of an element?

2022-05-19 08:29:34
Why can I have a template rule like this:

<xsl:template 
match="(sidRunwayTransition|sidCommonRoute|sidEnrouteTransition)/supplementalData">

But I cannot have a template rule like this:

<xsl:template
match="sid/(sidRunwayTransition|sidCommonRoute|sidEnrouteTransition)">

What is the context in which you find you can’t?

Here’s a document:

<root>
  <branch>
    <A/>
    <A/>
    <B/>
    <B/>
    <C/>
    <C/>
  </branch>
  <alternate>
    <A/>
    <A/>
    <B/>
    <B/>
    <C/>
    <C/>
  </alternate>
</root>

Here’s a stylesheet:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
                xmlns:xs="http://www.w3.org/2001/XMLSchema";
                exclude-result-prefixes="xs"
                version="3.0">

<xsl:output method="xml" encoding="utf-8" indent="no"/>

<xsl:mode on-no-match="shallow-copy"/>

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

<xsl:template match="(branch|alternate)/A">
  <xsl:copy>
    <m1/>
    <xsl:apply-templates/>
  </xsl:copy>
</xsl:template>

<xsl:template match="branch/(B|C)">
  <xsl:copy>
    <m2/>
    <xsl:apply-templates/>
  </xsl:copy>
</xsl:template>

</xsl:stylesheet>

And here’s what I get if I apply one to the other:

<?xml version="1.0" encoding="utf-8"?><root>
  <branch>
    <A><m1/></A>
    <A><m1/></A>
    <B><m2/></B>
    <B><m2/></B>
    <C><m2/></C>
    <C><m2/></C>
  </branch>
  <alternate>
    <A><m1/></A>
    <A><m1/></A>
    <B/>
    <B/>
    <C/>
    <C/>
  </alternate>
</root>

                                        Be seeing you,
                                          norm

--
Norman Tovey-Walsh <ndw(_at_)nwalsh(_dot_)com>
https://nwalsh.com/

There comes a time when a man must take himself, for better or worse,
as his portion.--Ralph Waldo Emerson
--~----------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
EasyUnsubscribe: http://lists.mulberrytech.com/unsub/xsl-list/1167547
or by email: xsl-list-unsub(_at_)lists(_dot_)mulberrytech(_dot_)com
--~--

Attachment: signature.asc
Description: PGP signature

<Prev in Thread] Current Thread [Next in Thread>