locked
Ignoring capitalisation in Xpath RRS feed

  • Question

  • User-61381467 posted

    I have an XML file which is the datasource of a grid view after applying this XSL transformation:

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output version="1.0" method="xml" indent="yes" />
    <xsl:template match="data">
    <xsl:element name="data">
    <xsl:apply-templates/>
    </xsl:element>
    </xsl:template>

    <xsl:template match="event">
    <xsl:element name="event">

    <xsl:attribute name="id">
    <xsl:value-of select="@id"/>
    </xsl:attribute>

    <xsl:attribute name="start">
    <xsl:value-of select="@start"/>
    </xsl:attribute>


    <xsl:attribute name="title">
    <xsl:value-of select="@title"/>
    </xsl:attribute>

    <xsl:attribute name="details">
    <xsl:value-of select="."/>
    </xsl:attribute>

    </xsl:element>
    </xsl:template>
    </xsl:stylesheet>

    The grid has an Xpath of "/data/event" and displays OK.

    On the click of a button I have this code:

    Dim eventCat As String

    eventCat = selCat.Value.ToUpper
    XmlDataSource1.XPath = "/data/event[contains(@details, '" + eventCat + "')]"

    This also works OK.

    What I would Like however is to find details which contain eventCat irrespective of capitalisation.

    I can't see how to capitalise the @details.

    TIA

    Andrew McG

    Wednesday, July 2, 2014 3:35 AM

Answers

  • User697462465 posted

    Hi zermattbs,

    Please try to change your xpath as below:

    XmlDataSource1.XPath = "/data/event[contains(translate(@details,'abcdefghijklmnopqrstuvwxyz','ABCDEFGHIJKLMNOPQRSTUVWXYZ'), '" + eventCat + "')]"
    
    

    Best Regards,
    Terry Guo

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, July 3, 2014 4:18 AM

All replies

  • User697462465 posted

    Hi zermattbs,

    There are no functions in xslt 1.0 to convert to uppercase or lowercase. Instead do the following:

    If it is required in a lot of places:

    Declare these two xsl variables (this is to make the xslt more readable)

    <xsl:value-of select="translate(@details,'abcdefghijklmnopqrstuvwxyz','ABCDEFGHIJKLMNOPQRSTUVWXYZ')"/>
    

    Best Regards,
    Terry Guo

    Wednesday, July 2, 2014 9:59 PM
  • User-61381467 posted

    Thanks for your help.

    You say 2 xsl variables, but you only show one; unless I am misunderstanding the terminology - that happens!

    I have placed it in my xsl file like this:

    <xsl:attribute name="details">
    <xsl:value-of select="."/>
    <xsl:value-of select="translate(@details,'abcdefghijklmnopqrstuvwxyz','ABCDEFGHIJKLMNOPQRSTUVWXYZ')"/>
    </xsl:attribute>

    Is this correct? And is anything more needed in the Xpath code, namely:

    eventCat = selCat.Value.ToUpper
    XmlDataSource1.XPath = "/data/event[contains(@details, '" + eventCat + "')]"

    Please excuse my ignorance...

    Regards

    Andrew McG

    Thursday, July 3, 2014 12:39 AM
  • User697462465 posted

    Hi zermattbs,

    Please try to change your xpath as below:

    XmlDataSource1.XPath = "/data/event[contains(translate(@details,'abcdefghijklmnopqrstuvwxyz','ABCDEFGHIJKLMNOPQRSTUVWXYZ'), '" + eventCat + "')]"
    
    

    Best Regards,
    Terry Guo

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, July 3, 2014 4:18 AM
  • User-61381467 posted

    Isn't it lovely when it works!

    I've been programming for many years, and that "trick" takes me back a long way!

    Many thanks again for a quick and exact response.

    I'll move on to the next problem...

    Andrew McG

    Thursday, July 3, 2014 7:34 PM