• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

xmltranform xsl issues

Community Beginner ,
Mar 12, 2008 Mar 12, 2008

Copy link to clipboard

Copied

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
TOPICS
Advanced techniques

Views

203

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Mar 14, 2008 Mar 14, 2008

Copy link to clipboard

Copied

LATEST
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>


Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation