Help - Conditionally Appending to Value using XSL?

Discussion in 'XML' started by jjouett, Sep 20, 2005.

  1. jjouett

    jjouett Guest

    I have XML that looks like the following:

    <top>
    <heart>
    <user>bob</user>
    <user>tim-o</user>
    <user>joe-i</user>
    <user>harvey</user>
    </heart>
    </top>

    and I need to have it look like the following:

    <top>
    <heart>
    <user>bob</user>
    <user>tim-out</user>
    <user>joe-in</user>
    <user>harvey</user>
    </heart>
    </top>

    In other words, I need to conditionally append text based on the data
    value (append 'n' if it ends in '-i', append 'ut' if it ends in '-o,
    otherwise do nothing). So far, I haven't come across an approach to
    accomplish this, but I am pretty much an XSLT newbie. Does anyone have
    suggestions on how to accomplish this?

    Thanks in advance
    jjouett, Sep 20, 2005
    #1
    1. Advertising

  2. jjouett

    Joris Gillis Guest

    Hi,

    Tempore 19:40:48, die Tuesday 20 September 2005 AD, hinc in foro {comp.text.xml} scripsit jjouett <>:

    > I need to conditionally append text based on the data
    > value (append 'n' if it ends in '-i', append 'ut' if it ends in '-o,
    > otherwise do nothing). So far, I haven't come across an approach to
    > accomplish this, but I am pretty much an XSLT newbie. Does anyone have
    > suggestions on how to accomplish this?


    <xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:eek:utput method="xml" indent="yes"/>

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

    <xsl:template match="text()[substring(.,string-length(.)-1,2)='-i']">
    <xsl:value-of select="."/>n<xsl:text/>
    </xsl:template>

    <xsl:template match="text()[substring(.,string-length(.)-1,2)='-o']">
    <xsl:value-of select="."/>ut<xsl:text/>
    </xsl:template>

    </xsl:stylesheet>

    regards,
    --
    Joris Gillis (http://users.telenet.be/root-jg/me.html)
    Don't send spam. I don't like it and it is illegal.
    Joris Gillis, Sep 20, 2005
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Amber
    Replies:
    0
    Views:
    803
    Amber
    Oct 7, 2003
  2. Replies:
    1
    Views:
    3,583
    A. Bolmarcich
    May 27, 2005
  3. Kourosh
    Replies:
    6
    Views:
    837
    Peter Flynn
    May 17, 2006
  4. Amber

    Conditionally Change a DataGrid Column Value...

    Amber, Oct 7, 2003, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    175
    Amber
    Oct 7, 2003
  5. Amber

    Conditionally Change a DataGrid Column Value...

    Amber, Oct 7, 2003, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    161
    Amber
    Oct 7, 2003
Loading...

Share This Page