tags:

views:

437

answers:

2

I am attempting to compose a style sheet that, given an XML input (obviously) and a parameter that specifies a "target", will produce a list of commands that match that target. Here is the style sheet as written:

<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
  <xsl:param name="target" select="cora_cmd"/>
  <xsl:output method="xml" indent="yes"/>
  <xsl:template match="command/program">
    <xsl:if test="@name=$target">
      <xsl:message terminate="no">found match <xsl:value-of select="$target"/>   </xsl:message>
      <xi:include xmlns:xi="http://www.w3.org/2003/XInclude"&gt;
        <xsl:attribute name="href"><xsl:value-of select="../@help"/></xsl:attribute>
      </xi:include>
    </xsl:if>
  </xsl:template>
</xsl:stylesheet>

I am invoking xsltproc to execute this style sheet as follows:

xsltproc --param target cora_cmd gen-commands.xsl commands.xml

The problem that I am encountering is that the parameter value for target does not seem to get set. At least the name that comes from the message appears to be an empty string and the test for xsl:if always fails. I am certain that this is due to some bone-headed mistake on my part but I've yet to recognise it. Does anybody know what I've done wrong?

+2  A: 

If I have understood the question correctly, I think you need to use 'stringparam' as the option to call xsltproc, assuming you are passing a string value to match, and not an XPath expression.

xsltproc --stringparam target cora_cmd gen-commands.xsl commands.xml
Tim C
+1  A: 

In your declaration of the 'target' parameter in the stylesheet, you should quote the @select value if you want it to function as a default value when the parameter is not used on the command line:

<xsl:param name="target" select="'cora_cmd'"/>
ChuckB