XML Editor
Sign up for a WebBoard account Sign Up Keyword Search Search More Options... Options
Chat Rooms Chat Help Help News News Log in to WebBoard Log in Not Logged in
Show tree view Topic
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Postnext
Dana PearsonSubject: tokenize a string with \r
Author: Dana Pearson
Date: 25 Sep 2012 08:16 PM

Hoping someone might enlighten me about the use of tokenizing a string based on a carriage return. I'm using SS Enterprise Edition 2010.

I've used the tokenize function frequently but never on carriage return. My requirement here is to split a dc:alternative title string (see below). The string before the first \r will go the subfield/@code='a', the remainder of the content will go into @code='b'.

There are relatively few of instances of such title strings but when they occur, the string must be split. I tried substring before and after functions first but without the result I wanted although I had no idea whether it would split on the first or any \r. It did nothing.

But using the tokenize function has the same result.

I'm using \r because that is the character separating the last character on a line; the next character is the first on the following line. I've tried using &#0D; as well although they are the same.

Finally, in another content analysis stylesheet, I tried the following for which I received the error message:

"At least one xsl:matching-substring or xsl:non-matching-substring element must be present."

This is what I suspected about the variable construction but received no such error messages; that is, the test for
contains(.[@rdf:parseType], '\r+')">
has no effect at all.

Am I wrong that \r is the character to split this string?

my variable:

<xsl:for-each select="dc:alternative">
<xsl:variable name="t1">
<xsl:if test="contains(.[@rdf:parseType], '\r+')">
<xsl:value-of select="tokenize(.[@rdf:parseType], '\r+')"/>
</xsl:if>
</xsl:variable>

analyze string variable:

<xsl:template match="dc:alternative">
<xsl:variable name="t1">
<xsl:if test="contains(.[@rdf:parseType], '\r+')">
<xsl:analyze-string
regex="\r+"
select=".[@rdf:parseType]"/>
<xsl:non-matching-substring>
<xsl:value-of select="."/>
</xsl:non-matching-substring>
</xsl:if>
</xsl:variable>
<title><xsl:value-of select="$t1"/></title>
</xsl:template>

First example of most common source element content; second and third, the target of my problem.

<dc:alternative rdf:parseType="Literal">Jin Shi Yuan</dc:alternative>

<dc:alternative rdf:parseType="Literal">Máguas Amorosas de Elmano
Idílio Por Bocage</dc:alternative>

<dc:alternative rdf:parseType="Literal">Galateia
Écloga
Primeira e Segunda Parte</dc:alternative>

thanks,
Dana Pearson

Postnext
Ivan PedruzziSubject: tokenize a string with \r
Author: Ivan Pedruzzi
Date: 25 Sep 2012 09:15 PM
Hi Dana,

The function "contains" does not take a regular expression as second argument but just a string
http://www.w3.org/TR/xpath-functions/#func-contains

The following should work and should be more efficient to execute

<xsl:variable name="t1">
<xsl:variable name="tokens" select="tokenize(.[@rdf:parseType], '&#xA;')"/>
<xsl:if test="count($tokens) > 1">
<xsl:value-of select="$tokens"/>
</xsl:if>
</xsl:variable>

If the match template for dc:alternative needs to output a title which does not contain cr, you could simply do

<xsl:template match="dc:alternative">
<title>
<xsl:if test="contains(.[@rdf:parseType], '&#xA;')">
<xsl:value-of select="$t1"/>
</xsl:if>
</title>
</xsl:template>

In the partial code posted we don't see the template which is supposed to split the string and save the result into different attributes. If the above does not help. please post the full XSLT code and a sample of the RDF input document.


Hope this helps
Ivan Pedruzzi
Stylus Studio Team

Postnext
Dana PearsonSubject: tokenize a string with \r
Author: Dana Pearson
Date: 25 Sep 2012 11:04 PM
thanks for your reply, Ivan.

I tried out your suggestion but got the peculiar message that the processor was expecting </xsl:foreach> at the closing element of your $tokens variable.

Don't understand the use of &#xA; since the XSLT editor says that the character I'm focusing on is $#0D;

Should have posted the relevant use of the variable earlier but was thinking that I was misunderstading something in my variable code.

Should have reviewed contain(). In any case here is what I'm trying to do.

<!-- alternate titles -->
<xsl:for-each select="dc:alternative">
<xsl:variable name="t1">
<xsl:if test="contains(.[@rdf:parseType], '&#xA;')">
<xsl:value-of select="tokenize(.[@rdf:parseType], '&#xA;')"/>
</xsl:if>
</xsl:variable>
<!--
<xsl:variable name="tokens" select="tokenize(.[@rdf:parseType], '&#xA;')"/>
<xsl:if test="count($tokens) > 1">
<xsl:value-of select="$tokens"/>
</xsl:if>
</xsl:variable> -->

<xsl:choose>
<xsl:when test="contains(.[@rdf:parseType], '&#xA;')">
<datafield tag="246" ind1="2" ind2=" ">
<subfield code="a">
<xsl:value-of select="normalize-space($t1[1])"/>
</subfield>
<subfield code="b">
<xsl:value-of select="normalize-space(concat($t1[2], $t1[3], $t1[4]))" separator=" "/>
</subfield>
</datafield>
</xsl:when>
<xsl:when test="not(contains(.[@rdf:parseType], '&#xA;'))">
<datafield tag="246" ind1="2" ind2=" ">
<subfield code="a">
<xsl:value-of select=".[@rdf:parseType]"/>
</subfield>
</datafield>
</xsl:when>
<xsl:otherwise></xsl:otherwise>
</xsl:choose>
<xsl:choose>
<xsl:when test="not(.[@rdf:parseType])">
<xsl:for-each select="rdf:Bag/rdf:li">
<datafield tag="246" ind1="2" ind2=" ">
<subfield code="a">
<xsl:value-of select="."/><xsl:text>.</xsl:text>
</subfield>
</datafield>
</xsl:for-each>
</xsl:when>
</xsl:choose>
</xsl:for-each>

thanks again,
Dana Pearson

Posttop
Ivan PedruzziSubject: tokenize a string with \r
Author: Ivan Pedruzzi
Date: 26 Sep 2012 07:46 PM

Dana was able to find a solution combining the information posted here with additional research on her hand.

Ivan Pedruzzi
Stylus Studio Team

 
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Download A Free Trial of Stylus Studio 6 XML Professional Edition Today! Powered by Stylus Studio, the world's leading XML IDE for XML, XSLT, XQuery, XML Schema, DTD, XPath, WSDL, XHTML, SQL/XML, and XML Mapping!  
go

Log In Options

Site Map | Privacy Policy | Terms of Use | Trademarks
Stylus Scoop XML Newsletter:
W3C Member
Stylus Studio® and DataDirect XQuery ™are from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2016 All Rights Reserved.