[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Creating a sequence from DSV strings

Subject: Creating a sequence from DSV strings
From: James Abley <james.abley@xxxxxxxxx>
Date: Thu, 21 Oct 2010 18:20:22 +0100
 Creating a sequence from DSV strings
Hi,

I am trying to pass in a DSV string parameter; e.g. "1234,356,6576" to
my stylesheet processing. The string may contain zero, one or many
members.

I'm trying to create a sequence using this parameter.

I then want to check to see whether an attribute in my source document
is contained within that sequence and do different processing based on
the result.

I'm struggling converting the string into a sequence.

I have these globals in my stylesheet:

	<!-- CSV list of article IDs which can be linked to -->
	<xsl:param name="article_ids" as="xs:string*" select="'392795'" />

	<xsl:variable name="article_id_list">
	    <xsl:analyze-string select="$article_ids" regex='([0-9]+)'>
            <xsl:matching-substring>
                <xsl:value-of select="regex-group(1)"/>
            </xsl:matching-substring>
            </xsl:analyze-string>
	</xsl:variable>

I have the following function intended to operate on the sequence.

    <!--
        XPath function which returns true if the sequence contains the
candidate item, otherwise false.
    -->
    <xsl:function name="local:sequence-contains" as="xs:boolean">
      <xsl:param name="candidate" as="xs:string" />
      <xsl:param name="seq" as="xs:string*"/>

      <xsl:choose>
        <xsl:when test="count($seq) = 0">
            <xsl:message>Sequence is empty</xsl:message>
            <xsl:value-of select="false()"/>
        </xsl:when>
        <xsl:otherwise>
            <xsl:variable name="car" select="$seq[1]" />
            <xsl:variable name="cdr" select="subsequence($seq, 2)" />
            <xsl:choose>
                <xsl:when test="$car = $candidate">
                    <xsl:message>Sequence <xsl:value-of
select="$seq"/> contains <xsl:value-of
select="$candidate"/></xsl:message>
                    <xsl:value-of select="true()" />
                </xsl:when>
                <xsl:otherwise>
                    <xsl:value-of
select="local:sequence-contains($candidate, $cdr)" />
                </xsl:otherwise>
            </xsl:choose>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:function>

I'm then calling the function in an <xsl:template/> like so:

    <xsl:template match="xref[local:sequence-contains(@rid, $article_id_list)]">
     ...
    </xsl:template>

I'm seeing debug output that the article_id_list sequence is empty,
even though I have the default value defined for the article_ids
parameter and I'm not passing a different value into the transform.

1. Can someone point out what's wrong with the way I'm trying to
define create a sequence in the variable declaration?
2. Is my function correct? I was a little dubious about using
<xsl:value-of /> to try to return the xs:boolean result. Anything
wrong with it?

Thanks for your time.

Cheers,

James

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.