| Subject: RE: [xsl] Copying and updating selectively From: "John Reid" <John.Reid@xxxxxxxxxxxxxxx> Date: Sun, 27 Jul 2003 07:31:43 +1000 | 
Thanx Américo Albuquerque,
That worked well, and taught me something.
Another q
If I was to add another condition that is higher up the tree how/where
would I best test it
Ie
The same template but this time I am asking only to test those players
where pword a parameter = @pword. This is really 2 problems for me, I
guess I would like to know the best way to pass a parameter to a
template as a condition of entry and to also know how to test further up
the tree.
Non pasaran
John Reid
  <xsl:param name="varFrom" select="'20030809'"/>
  <xsl:param name="varTo" select="'20030812'"/>
  <xsl:param name="varPword" select="'843208'"/>
  <xsl:template match="node()|@*">
    <xsl:copy>
      <xsl:apply-templates select="node()|@*"/>
    </xsl:copy>
  </xsl:template>
  <xsl:template match="yes">
    <!-- this variable is been used as a shortcut to current()/@ID in
the
select statement -->
    <xsl:variable name="id" select="@ID"/>
    <xsl:copy>
      <!-- here I'm sellecting all non text nodes, all text nodes if the
current node ID attribute is not between $varFrom and $varTo and all
attribute nodes -->
      <xsl:apply-templates select="node()[not(self::text())] |
text()[not($id >= $varFrom and $id <= $varTo)] | @*"/>
    </xsl:copy>
  </xsl:template>
<player pword="843208">
  <dates>
    <yes ID="20030722" WE="Tu">A</yes>
    <yes ID="20030729" WE="Tu">A</yes>
    <yes ID="20030805" WE="Tu">A</yes>
    <yes ID="20030809" WE="Sa">D</yes>
    <yes ID="20030810" WE="Su">D</yes>
    <yes ID="20030812" WE="Tu">D</yes>
    <yes ID="20030819" WE="Tu">A</yes>
    <yes ID="20030826" WE="Tu">A</yes>
  </dates>
</player>
Will give this result (no D's):
<player pword="843208">
  <dates>
    <yes ID="20030722" WE="Tu">A</yes>
    <yes ID="20030729" WE="Tu">A</yes>
    <yes ID="20030805" WE="Tu">A</yes>
    <yes ID="20030809" WE="Sa"/>
    <yes ID="20030810" WE="Su"/>
    <yes ID="20030812" WE="Tu"/>
    <yes ID="20030819" WE="Tu">A</yes>
    <yes ID="20030826" WE="Tu">A</yes>
  </dates>
</player>
-----Original Message-----
From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx
[mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx] On Behalf Of Américo
Albuquerque
Sent: Saturday, 26 July 2003 11:24 PM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: RE: [xsl] Copying and updating selectively
Hi
> -----Original Message-----
> From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx 
> [mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx] On Behalf Of John Reid
> Sent: Saturday, July 26, 2003 11:49 AM
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: RE: [xsl] Copying and updating selectively
> 
> 
> Um some small changes, but still no result. The first 
> apply-template gets applied, does it then apply itself 
> recursively,without falling thru to the next apply-template? 
> If so does the copy statement build a structure that is then 
> applied once the recursion ends??
> 
> <xsl:template match="player/dates">
> <xsl:copy>
>     <xsl:apply-templates 
> select="@*|node()[not(../@pword=$varPMKey)]"/>
>     <xsl:apply-templates select="@*|node()[yes/@ID < $varFrom]"/>
>     <xsl:apply-templates select="@*|node()[yes/@ID > 
> $varTo]"/> </xsl:copy> </xsl:template>
> 
> g'day,
> 
> i got so far with this and then came up empty. I want to 
> update/copy a xml file updating any yes node to null (i guess 
> deleting the text node is the better way to put it). So that 
> i start with ONE and end with TWO on the condition that the 
> @ID date is within the two date parameters. The code at the 
> bottom is my starting attempt. The two date parameters are 
> $varFrom=20030806 and $varTo=20030814
> 
> any thoughts
> 
> salud John Reid
This is a variation of the identity template. Copy all nodes and change
just
that you want to change
  <xsl:param name="varFrom" select="'20030809'"/>
  <xsl:param name="varTo" select="'20030812'"/>
  <xsl:template match="node()|@*">
    <xsl:copy>
      <xsl:apply-templates select="node()|@*"/>
    </xsl:copy>
  </xsl:template>
  <xsl:template match="yes">
    <!-- this variable is been used as a shortcut to current()/@ID in
the
select statement -->
    <xsl:variable name="id" select="@ID"/>
    <xsl:copy>
      <!-- here I'm sellecting all non text nodes, all text nodes if the
current node ID attribute is not between $varFrom and $varTo and all
attribute nodes -->
      <xsl:apply-templates select="node()[not(self::text())] |
text()[not($id >= $varFrom and $id <= $varTo)] | @*"/>
    </xsl:copy>
  </xsl:template>
Applied to (the A's is to see if those nodes get copied or not):
<player>
  <dates>
    <yes ID="20030722" WE="Tu">A</yes>
    <yes ID="20030729" WE="Tu">A</yes>
    <yes ID="20030805" WE="Tu">A</yes>
    <yes ID="20030809" WE="Sa">D</yes>
    <yes ID="20030810" WE="Su">D</yes>
    <yes ID="20030812" WE="Tu">D</yes>
    <yes ID="20030819" WE="Tu">A</yes>
    <yes ID="20030826" WE="Tu">A</yes>
  </dates>
</player>
Will give this result (no D's):
<player>
  <dates>
    <yes ID="20030722" WE="Tu">A</yes>
    <yes ID="20030729" WE="Tu">A</yes>
    <yes ID="20030805" WE="Tu">A</yes>
    <yes ID="20030809" WE="Sa"/>
    <yes ID="20030810" WE="Su"/>
    <yes ID="20030812" WE="Tu"/>
    <yes ID="20030819" WE="Tu">A</yes>
    <yes ID="20030826" WE="Tu">A</yes>
  </dates>
</player>
(...)
 
Regards,
Américo Albuquerque
 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
| Current Thread | 
|---|
| 
 | 
| <- Previous | Index | Next -> | 
|---|---|---|
| RE: [xsl] Copying and updating sele, Américo Albuquerque | Thread | RE: [xsl] Copying and updating sele, Américo Albuquerque | 
| [xsl] encoding and NCRs; source doc, Mike Brown | Date | Re: [xsl] Whitespace in Table Cells, Wendell Piez | 
| Month |