Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does XSLT have a Split() function?

I have a string in a node and I'd like to split the string on '?' and return the last item in the array.

For example, in the block below:

<a>     <xsl:attribute name="href">         /newpage.aspx?<xsl:value-of select="someNode"/>     </xsl:attribute>     Link text </a> 

I'd like to split the someNode value.

Edit: Here's the VB.Net that I use to load the Xsl for my Asp.Net page:

Dim xslDocPath As String = HttpContext.Current.Server.MapPath("~/App_Data/someXslt.xsl") Dim myXsltSettings As New XsltSettings() Dim myXMLResolver As New XmlUrlResolver()  myXsltSettings.EnableScript = True myXsltSettings.EnableDocumentFunction = True  myXslDoc = New XslCompiledTransform(False) myXslDoc.Load(xslDocPath, myXsltSettings, myXMLResolver)  Dim myStringBuilder As New StringBuilder() Dim myXmlWriter As XmlWriter = Nothing  Dim myXmlWriterSettings As New XmlWriterSettings() myXmlWriterSettings.ConformanceLevel = ConformanceLevel.Auto myXmlWriterSettings.Indent = True myXmlWriterSettings.OmitXmlDeclaration = True  myXmlWriter = XmlWriter.Create(myStringBuilder, myXmlWriterSettings)  myXslDoc.Transform(xmlDoc, argumentList, myXmlWriter)  Return myStringBuilder.ToString() 

Update: here's an example of splitting XML on a particular node

like image 239
travis Avatar asked Sep 25 '08 22:09

travis


People also ask

How do you break for each in XSLT?

There is no such a thing as break in an XSLT for-each loop. xsl:if/@test is pretty much all you can do. The other way would be to include this condition within the for-each/@select.

How do you substring values in XSLT?

Substring is primarily used to return a section of a string or truncating a string with the help of the length provided. XSLT is incorporated with XPath while manipulating strings of text when XSLT access. The Substring function takes a string as an argument with the numbers one or two and an optional length.

What is text () in XSLT?

XSLT <xsl:text> The <xsl:text> element is used to write literal text to the output. Tip: This element may contain literal text, entity references, and #PCDATA.

What is substring after in XSLT?

Definition of XSLT substring-after Function. The substring-after function returns a part out of the string declared in the string argument that is specified after the substring. If a second string is empty it returns an empty string as a result. String functions determine the manipulation of strings of text.


1 Answers

Use a recursive method:

<xsl:template name="output-tokens">     <xsl:param name="list" />      <xsl:variable name="newlist" select="concat(normalize-space($list), ' ')" />      <xsl:variable name="first" select="substring-before($newlist, ' ')" />      <xsl:variable name="remaining" select="substring-after($newlist, ' ')" />      <id>         <xsl:value-of select="$first" />      </id>     <xsl:if test="$remaining">         <xsl:call-template name="output-tokens">             <xsl:with-param name="list" select="$remaining" />          </xsl:call-template>     </xsl:if> </xsl:template> 
like image 197
mortenbpost Avatar answered Sep 23 '22 19:09

mortenbpost