xsl-list
[Top] [All Lists]

RE: Replacing portion of element name

2003-11-24 12:34:51
Note that you have a space in your element...which is not allowed in xml.

Its relatively easy to get the name of a element and do something with
it...no need for extension functions, though if u were to use one I would
recc exslt regexp:replace at EXSLT
http://www.exslt.org/regexp/functions/replace/index.html 


If I have this as an xml file;

Xml document

<?xml version="1.0"?>
<commander_s_tracked_station_list>
test
</commander_s_tracked_station_list>

Then something like the following will print out

<xsl:value-of select="local-name(*)"/>

The name of the element...now you need to deal with replacing the
underscores with spaces, or the complex part to determine when to replace an
underscore with an apostrophe. Hmmmm

You could first place your element name in a variable to work with;

<xsl:variable name="myvar" select="local-name(*)"/>

Then easily convert underscores into spaces, using the translate() command;

<xsl:variable name="myvar1" select="translate($myvar,'_',' ')"/>

Then is the tricky part ( I have listed it in full again )

        
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
        <xsl:output method = "html" encoding="Windows-1252" />
        
        <xsl:template match="/">        

        <xsl:variable name="myvar" select="local-name(*)"/>
        
        <xsl:variable name="myvar1" select="translate($myvar,'_',' ')"/>


<xsl:value-of select="substring-before($myvar1,' s')"/>'s<xsl:value-of
select="substring-after($myvar1,'s')"/>
        
        
        </xsl:template>
</xsl:stylesheet>


You can come up with something iterative, but the below is the operative
term

<xsl:value-of select="substring-before($myvar1,' s')"/>'s<xsl:value-of
select="substring-after($myvar1,'s')"/>

Gl, jim fuller

-----Original Message-----
From: owner-xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
[mailto:owner-xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com] On Behalf Of 
Boyd, Eddie
Sent: Monday, November 24, 2003 6:51 PM
To: 'xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com'

Hi all,

I have an element name <commander_s_ tracked_station_list>, among others,
that needs to be transformed to a string with an apostrophe followed by an
s, i.e. "commander's tracked...".  How can I get the 's without using
external functions?  Is this possible with XSLT/XPATH 1.0?  I can easily
convert the underscores to a non-breaking space using the translate
function, but I have not been able to crack the code to make the apostrophe
appear in the appropriate place.  Any suggestions would be greatly
appreciated.

Thank you,
Eddie

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list