tags:

views:

862

answers:

3

I have this xslt:

  <xsl:template name="dumpDebugData">
    <xsl:param name="elementToDump" />
    <xsl:for-each select="$elementToDump/@*">
      <xsl:text>&#10;</xsl:text>    <!-- newline char -->
      <xsl:value-of select="name()" /> : <xsl:value-of select="." />
    </xsl:for-each>
  </xsl:template>

i want to display every element (as in name/value), how do i call this template?

+2  A: 

Try something like this:

<xsl:call-template name="dumpDebugData">
    <xsl:with-param name="elementToDump">foo</xsl:with-param>
</xsl:call-template>
Andrew Hare
Is there a reason this was downvoted?
Andrew Hare
because is passes a string into the template, not a nodeset?
samjudson
Very true, but it was just a simple example of how to call a template with parameters.
Andrew Hare
+1  A: 

Since the template expects a node set, you must do:

<xsl:call-template name="dumpDebugData">
  <xsl:with-param name="elementToDump" select="some/xpath" />
</xsl:call-template>
Tomalak
A: 

There are a number of issues in your original XSLT, so I worked through it and got you the following code which does what you want I believe:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output indent="yes"/>
<xsl:strip-space elements="*"/>

<xsl:template match="element()">
    <xsl:call-template name="dumpDebugData">
     <xsl:with-param name="elementToDump" select="."/>
    </xsl:call-template>
    <xsl:apply-templates/>
</xsl:template>

<xsl:template name="dumpDebugData">
    <xsl:param name="elementToDump" />
    Node: <xsl:value-of select="name()" /> : <xsl:value-of select="text()" />
  <xsl:for-each select="attribute::*">
    Attribute: <xsl:value-of select="name()" /> : <xsl:value-of select="." />
  </xsl:for-each>
</xsl:template>

</xsl:stylesheet>
samjudson