[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] Copy part of the file if some conditions are applied


Subject: Re: [xsl] Copy part of the file if some conditions are applied
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Thu, 08 Jun 2006 20:47:32 +0100

Hi Maria,

I want to copy some parts of the tree, under certains
conditions, for example:

The starting point for your stylesheet should be the identity template, which copies everything:


<xsl:template match="node()|@*">
  <xsl:copy>
    <xsl:apply-templates select="@*|node()" />
  </xsl:copy>
</xsl:template>

You can then add empty templates for the various cases where you *don't* want particular elements to be copied...

If <pred> in <tagB> contains the caracter 'z' then
nothing should be copy from the <tagA> (and that
<tagA> should not appear in the transformation).

In other words, a <tagA> whose child <tagB>'s <pred> contains the letter 'z' should not be copied.


<xsl:template match="tagA[contains(tagB/pred, 'z')]" />

Otherwise, I have to check if any <pred> tag inside
<tagC> contains 'z', in that case, I cannot copy
anyhing from the father tag (D or E).

In other words, any child of <tagC> whose <pred> contains the letter 'z' should not be copied.


<xsl:template match="tagC/*[contains(pred, 'z')]" />

Is important to mention that in case I have just one
<tagD> inside <tagC>, and that <tagD> contains 'z',
nothing including <tagA> should be copied.

<xsl:template match="tagA[count(tagC/tagD) = 1 and contains(tagC/tagD/pred, 'z')]" />

I hope this gets you started.

Cheers,

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


Current Thread