Skip to main content
Participating Frequently
March 13, 2008
Question

xmltranform xsl issues

  • March 13, 2008
  • 1 reply
  • 229 views
Hello, I have been tring to pull data from xml document using xmltransform. The xmltranform works and I am able to get data from the xml document, but having trouble when there are multiple data of the same nature. I can not pull the names or the Phone number. I am new to xml, so be gentle with me. The code I have here was gleaned from multiple websites. I have included the xml, xsl stylesheet code and the html output. Thanks for any help in advance. Craig
This topic has been closed for replies.

1 reply

March 14, 2008
It's easier to use params and additional templates... something like this:

<xsl:template match="contact" >
<!-- The values for the params are set in other templates -->
<xsl:param name="fName" />
<xsl:param name="lName" />
<xsl:param name="emailAddr" />
<xsl:for-each select="name">
<xsl:call-template name="getName">
<xsl:with-param name="fName" />
<xsl:with-param name="lName" />
</xsl:call-template>
</xsl:for-each>
Name: <xsl:value-of select="$fName"><xsl:text> </xsl:text><xsl:value-of select="$lName" /><br />

<!-- You really don't need another template here, but you can use one -->
<!-- It can be written: Email: <value-of select="email" /> but this is another demo -->
<xsl:apply-templates select="email">
<xsl:with-param name="emailAddr" />
</xsl:apply-templates>
Email: <xsl:value-of select="$emailAddr" /><br />
</xsl:template>

<!-- This template "fills" names dependent upon the "part" attibute -->
<!-- Values set here are available to the template that called this one -->
<xsl:template name="getName">
<xsl:param name="fName" />
<xsl:param name="lName" />
<xsl:choose>
<xsl:when test="@part='first'">
<xsl:param name="fName" select="." />
</xsl:when>
<xsl:otherwise>
<xsl:param name="lName" select="." />
</xsl:otherwise>
</xsl:choose>
</xsl:template>

<xsl:template match="email">
<xsl:with-param name="emailAddr" select="." />
</xsl:template>