OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

 


 

   Re: XSLT Question: using the starts-with() string function

[ Lists Home | Date Index | Thread Index ]
  • From: "Roger L. Costello" <costello@mitre.org>
  • To: Keith Visco <kvisco@mitre.org>
  • Date: Mon, 21 Jun 1999 13:09:44 -0400

Keith Visco wrote:
> 
> Roger,
> 
> you are passing your first parameter as a String literal, instead of an
> expression.
> 
> try removing the quotes from './text()' and just use ./text() or just
> text() since the "." (Identity) should be implicit in this case.
> 

Thanks Keith.  Using text() worked like a charm:

<xsl:template match="location" >
     <xsl:if test="starts-with(text(),'ICAO')">
             <location_ICAO>
                 <xsl:apply-templates/>
             </location_ICAO>
     </xsl:if>
     <xsl:if test="starts-with(text(),'LatLon')">
             <location_LatLon>
                 <xsl:apply-templates/>
             </location_LatLon>
     </xsl:if>
</xsl:template>

/Roger


> --Keith
> 
> "Roger L. Costello" wrote:
> >
> > Hi folks,
> >
> > I am having some trouble using XSLT's starts-with() string function.
> > Below is a snippet of some XML:
> >
> > <location>
> >     ICAO: Boston
> > </location>
> > <location>
> >     LatLon: 74.31W, 106.5N
> > </location>
> >
> > Note how the content of the <location> element either starts with ICAO
> > or with LatLon.
> >
> > I would like to write a template rule for the <location> element
> > that checks to see what its content starts with.  If it starts with
> > ICAO then it should do one thing.  It is starts with LatLon it
> > should do another thing.  Here is my (failed) attempt at this template
> > rule:
> >
> > <xsl:template match="location" >
> >     <xsl:if test="starts-with('./text()','ICAO')">
> >             <location_ICAO>
> >                 <xsl:apply-templates/>
> >             </location_ICAO>
> >     </xsl:if>
> >     <xsl:if test="starts-with('./text()','LatLon')">
> >             <location_LatLon>
> >                 <xsl:apply-templates/>
> >             </location_LatLon>
> >     </xsl:if>
> > </xsl:template>
> >
> > When I run this through James Clark's XT processor I get no output
> > for this template rule.  What am I doing wrong?
> >
> > Also, I found that if I user the xsl:choose construct (rather than
> > the sequence of xsl:if statements) I get an "invalid token" error
> > message.  Anyone know that that's all about?
> >
> > /Roger


xml-dev: A list for W3C XML Developers. To post, mailto:xml-dev@ic.ac.uk
Archived as: http://www.lists.ic.ac.uk/hypermail/xml-dev/ and on CD-ROM/ISBN 981-02-3594-1
To (un)subscribe, mailto:majordomo@ic.ac.uk the following message;
(un)subscribe xml-dev
To subscribe to the digests, mailto:majordomo@ic.ac.uk the following message;
subscribe xml-dev-digest
List coordinator, Henry Rzepa (mailto:rzepa@ic.ac.uk)






 

News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 2001 XML.org. This site is hosted by OASIS