I'm having a problem with an XSL script, using perl's XML::XSLT library. The code I'm dealing with is below:

The XML:

<eprint><eprint_status>archive</eprint_status><eprintid>3</eprintid><userid>5</userid><datestamp>2004-06-04</datestamp><type>journalp</type><abstract>Issues about young people&#x2019;s use of public and community spaces are now commonly raised in many countries. As urban space becomes more intensely used and the patterns of use of various types of space changes so a range of tensions have emerged for a range of parties including local government, shopping centre management, youth services and young people themselves. (This article is based on a paper delivered at the International Conference on Young People and Social Exclusion, University of Strathclyde, Glasgow, 10 September 1999.)</abstract><creators><item><id>Crane, Philip</id><name><family>Crane</family><given>Philip R.</given></name></item></creators><editors><item><name><family>Milburn</family><given>Ted</given></name></item></editors><ispublished>pub</ispublished><keywords>Youth; Young people; Public space; Inclusion</keywords></eprint>

The XSL:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output method="xml" indent="yes" omit-xml-declaration="yes"/>

<xsl:strip-space elements="*"/>

<!-- Set variables -->

<!-- Output everything unchanged, except when we hit an element that has a matching template below (ie. element 'copyrightowner') -->

<xsl:template match="*">
   <xsl:copy>
        <xsl:copy-of select="@*"/>
        <xsl:apply-templates/>
   </xsl:copy>
</xsl:template>

<xsl:template match="keywords">
   <keywords>
           <xsl:call-template name="split">
                <xsl:with-param name="string" select="."/>
           </xsl:call-template>
   </keywords>
</xsl:template>
<xsl:template name="split">
   <xsl:param name="string"/>
   <xsl:choose>
        <xsl:when test="contains($string,', ')">
          <item>
           <xsl:value-of select="substring-before($string,', ')"/>
          </item>
           <xsl:variable name="remainder" select="substring-after($string,', ')"/>
           <xsl:call-template name="split">
                <xsl:with-param name="string" select="$remainder"/>
           </xsl:call-template>
        </xsl:when>
        <xsl:when test="contains($string,'; ')">
          <item>
           <xsl:value-of select="substring-before($string, '; ')"/>
          </item>
           <xsl:variable name="remainder" select="substring-after($string, '; ')"/>
           <xsl:call-template name="split">
                <xsl:with-param name="string" select="$remainder"/>
           </xsl:call-template>
        </xsl:when>
        <xsl:otherwise>
          <item>
           <xsl:value-of select="$string"/>
          </item>
        </xsl:otherwise>
   </xsl:choose>
</xsl:template>

</xsl:stylesheet>

When I run this through my perl script, the XSL that splits the keywords by a separator is not working properly. What happens is I get this:

<keywords><item>.</item></keywords>

It appears that the parameter I set within the call-template declaration is not getting the value of the keywords field using the standard XSL '.' (period) variable. I don't know why; it works in every other XSL transformation that I've configured for this script (I removed the others and have just been testing with the keywords one).

Can anyone explain this to me? I'm almost at the hair-tearing-out point :)

Thanks,
Guy

Ignore the above, I've since discovered that XML::XSLT's xsl:call-template directive doesn't support the 'select' attribute in xsl:with-param tags that are used during the template call.

I'll try XML::LibXSLT or Sablotron instead.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.