Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

explode a string with xslt

Status
Not open for further replies.

axman505

Technical User
Jun 20, 2001
489
0
0
US
Hello,

What i am trying to do is take the variable $courseID frmo the below xslt sheet and explode it on _. So far i have not had any luck, does anyone have any suggestions? Thanks!

Code:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="[URL unfurl="true"]http://www.w3.org/1999/XSL/Transform">[/URL]

<xsl:template match="/">
<instrcourses>

        <xsl:for-each select="//membership">
        <course>
                <xsl:attribute name="id">
                        <xsl:value-of select="sourcedid/id" />
                </xsl:attribute>

                <xsl:variable name="courseID">
                        <xsl:value-of select="sourcedid/id" />
                </xsl:variable>

                <courseid>
                        <xsl:value-of select="sourcedid/id" />
                </courseid>

                <xsl:for-each select="member">
                        <user>
                                <courseid><xsl:value-of select="$courseID" /></courseid>
                                <idnumber><xsl:value-of select="sourcedid/id" /></idnumber>
                                <role><xsl:value-of select="role/@roletype" /></role>
                        </user>
                </xsl:for-each>

        </course>
        </xsl:for-each>

</instrcourses>
</xsl:template>
</xsl:stylesheet>
 
use

Code:
<?xml version="1.0"?>
<xsl:stylesheet version="2.0" xmlns:xsl="[URL unfurl="true"]http://www.w3.org/1999/XSL/Transform">[/URL]
<xsl:template match="course">
<xsl:value-of select="tokenize(., '_+')"/>
</xsl:template>
</xsl:stylesheet>

You have to use xsl version 2.0 tho for this.
 
The problem is that we are on an old redhat box (redhat 9), and it doesnt appear to support xslt 2.0
 
are u using java to do this transform?

if so, just install the new Xalan parser and the new sdk from sun.

 
but you must be using some sort of transformation engine to do the transform?

can you give me an example of what you are writing in the shell to do this plz.

 
sure. its:

xsltproc -o roster_test.xml class_roster.xslt ../xml/myxmlfile.XML

I may try to get the files on a newer box.
 
i can't find anything on the internet that states xsltproc supports xslt 2.0 anywhere, so theres probably no point in moving to another box.

you could just use vi's search/replace in the xml to replace all the _'s or pre-remove these _'s when you generate? the xml

Or, just install the java sdk and xalan or saxon. seriously, why use a penknife when you could be using a chainsaw?

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top