1

Sorry for the dumb question, but string handling in xsl 1.0 is not one of my strong points. I'm looking for a way of extracting a string held between pseudo html tags. EG.

<xsl:variable name="test">
    This is a string <link>http://www.stackoverflow.com</link> and some more stuff here
</xsl:variable>

The idea being to end up with 2 further variables that would contain.

var1 = http://www.stackoverflow.com and var2 = This is a string and some more stuff here

Like I say, sorry it's a dim question. Thanks.

1 Answer 1

1

Here is how to do this:

<xsl:stylesheet version="1.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:output omit-xml-declaration="yes" indent="yes"/>
 <xsl:strip-space elements="*"/>

 <xsl:variable name="test">
  This is a string <link>http://www.stackoverflow.com</link> and some more stuff here
 </xsl:variable>

 <xsl:variable name="vTestNodeset" select="document('')/*/xsl:variable[@name='test']"/>

 <xsl:variable name="var1" select="string($vTestNodeset/link)"/>

 <xsl:variable name="var2">
  <xsl:copy-of select="$vTestNodeset/text()"/>
 </xsl:variable>

 <xsl:template match="/">
     "<xsl:value-of select="$var1"/>"
============    
     "<xsl:value-of select="$var2"/>"
============    
     "<xsl:value-of select="normalize-space($var2)"/>"
 </xsl:template>
</xsl:stylesheet>

When this transformation is applied on any XML document (not used), the wanted result is produced:

     "http://www.stackoverflow.com"
============    
     "
  This is a string  and some more stuff here
 "
============    
     "This is a string and some more stuff here"
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.