You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@xalan.apache.org by Simon Wallington <si...@artsoft.co.uk> on 2001/03/01 13:08:13 UTC

Template matching on child and value

Hi,

I have a simple .xml file that contains a structure like this:

  <ROOT>
  <COLUMN_COLLECTION>

    <COLUMN TYPE="string" MAXLENGTH="20" SIZE="10">
      <ID>
        TIMESTAMP
      </ID>
      <CAPTION>
        Timestamp
      </CAPTION>
    </COLUMN>

    ... lots more COLUMN elements
  </COLUMN_COLLECTION>
  ..
  <OTHER_ELEMENTS/>
  ..
  </ROOT>

In the .xsl file I want to invoke parsing of one specific COLUMN, so I
have something like:

  <xsl:template match="SOMEWHERE_ELSE">
    <xsl:apply-templates
select="/ROOT/COLUMN_COLLECTION/COLUMN[ID='TIMESTAMP']"/>
</xsl:template>

, plus some simple instructions for what to do with a COLUMN:

  <xsl:template match="COLUMN">blaa blaa blaa</xsl:template>

This works beautifully when I test in IE5, which also supports using
context() to apply the value dynamically (something I also need to do).
When I run this in Xalan for Java 2 it doesn't find the COLUMN and
produces no output from this line.

Please help!

Simon Wallington
Artsoft Limited
106 High Street
Ripley
Surrey  GU23  6AN
Tel:       +44 (0) 1483 211155
Fax:      +44 (0) 1483 211166

Website: http://www.artsoft.co.uk
Email:     mailto:simon.wallington@artsoft.co.uk

Artsoft. 505 Montgomery, 10th/11th Floors, San Francisco, CA 94111, USA
Tel:       +1 415 887 3512


________________________________________________________________________
This message has been checked for all known viruses, by Star Internet, 
delivered through the MessageLabs Virus Control Centre. 
For further information visit:
http://www.star.net.uk/stats.asp


Re: Template matching on child and value

Posted by Gary L Peskin <ga...@firstech.com>.
Simon Wallington wrote:
> 
> Hi,
> 
> I have a simple .xml file that contains a structure like this:
> 
>   <ROOT>
>   <COLUMN_COLLECTION>
> 
>     <COLUMN TYPE="string" MAXLENGTH="20" SIZE="10">
>       <ID>
>         TIMESTAMP
>       </ID>
>       <CAPTION>
>         Timestamp
>       </CAPTION>
>     </COLUMN>
> 
>     ... lots more COLUMN elements
>   </COLUMN_COLLECTION>
>   ..
>   <OTHER_ELEMENTS/>
>   ..
>   </ROOT>
> 
> In the .xsl file I want to invoke parsing of one specific COLUMN, so I
> have something like:
> 
>   <xsl:template match="SOMEWHERE_ELSE">
>     <xsl:apply-templates
> select="/ROOT/COLUMN_COLLECTION/COLUMN[ID='TIMESTAMP']"/>
> </xsl:template>
> 
> , plus some simple instructions for what to do with a COLUMN:
> 
>   <xsl:template match="COLUMN">blaa blaa blaa</xsl:template>
> 
> This works beautifully when I test in IE5, which also supports using
> context() to apply the value dynamically (something I also need to do).
> When I run this in Xalan for Java 2 it doesn't find the COLUMN and
> produces no output from this line.
> 
> Please help!
> 

Simon --

I'm not sure why this works in IE5.  In XalanJ2, try

<xsl:apply-templates
  
select="/ROOT/COLUMN_COLLECTION/COLUMN[normalize-space(ID)='TIMESTAMP']"/>

or include

<xsl:strip-space elements="ROOT">

which will probably make things go faster overall.

The expression [ID='TIMESTAMP'] is a comparison between a node-set (ID)
and a string ('TIMESTAMP').  This is done by comparing the string-value
of each ID node in the node-set against the value 'TIMESTAMP'.  The
string-value of the ID node is "the concatenation of the string-values
of all text node descendants of the element node in document order".  ID
has one text node descdant whose value is a new-line followed by a bunch
of spaces followed by the word TIMESTAMP followed by a new-line followed
by more spaces.

HTH,
Gary