Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 25th, 2008, 03:39 PM
Registered User
 
Join Date: May 2005
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to Naughtytrini Send a message via Yahoo to Naughtytrini
Default Passing attribute name into XSLT to pull content

Hello,

I'm using an XML feed to create a site with some of the feed's content. Here is a small sample of the feed:

<rates>
   <cardInfo>
      <card id="name">
         <currency>USD</currency>
     <description/>
     <dialingInstructions></dialingInstructions>
     <directions>
        <direction name="Canada" value="true"/>
        <direction name="Hawaii" value="true"/>
     </directions>
     <expireDate>1 Year (365 Days)</expireDate>
     <largeImage>/crd_images/clearchoice.gif</largeImage>
     <maintenanceFee>0</maintenanceFee>
     <maintenanceFeeDesc/>
     <taxesPercent>17</taxesPercent>
     <name>CLEAR CHOICE</name>
     <prices>
        <price denomination="20" price="20"/>
        <price denomination="50" price="50"/>
         </prices>
     <publicPhoneFee>0.99</publicPhoneFee>
     <publicPhoneFeeDesc/>
     <recharge>True</recharge>
     <autoRecharge>True</autoRecharge>
     <LocalAccessGroup>0</LocalAccessGroup>
     <recommendationsId/>
     <rounding>1 minute</rounding>
     <servicePhones>
        <servicePhone>8777778954</servicePhone>
     </servicePhones>
     <accessNumber>8007454065</accessNumber>
      </card>
      <cardRate>
         <connectionFee>0</connectionFee>
     <smallImage></smallImage>
     <localRate>0.114</localRate>
     <productLink></productLink>
      </cardRate>
   </cardInfo>
</rates>

What I want to do is pass a card name in my XSLT with a param name then match the param name with the card node's id attribute and pull only that particular content. Here is what I have so far:

<?xml version="1.0" encoding="utf-8"?>
 <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:output method="html" encoding="utf-8"/>

 <xsl:param name="clear" select="rates/cardInfo/card/@id[CLEAR CHOICE]" />
 <xsl:decimal-format name="us" decimal-separator="." grouping-separator="," />

    <xsl:template match="/">
    <xsl:for-each select="rates/cardInfo/card/@id">
       <xsl:call-template name="one">
        <xsl:with-param name="clear" select="?" />
       </xsl:call-template>
    </xsl:for-each>
    </xsl:template>

    <xsl:template name="one">
    <xsl:param name="clear" select="rates/cardInfo/card/@id" />
      <div id="image"><a href="{rates/cardInfo/cardRate/productLink}">{rates/cardInfo/card/largeImage}</a></div>
      <div id="rate">
          <div class="name"><xsl:value-of select="$clear" /></div>
          <div class="rates"><xsl:value-of select="format-number(rates/cardInfo/cardRate/localRate, '##.00', 'us')"/>c per minute</div>
          <div class="button"><a href="{rates/cardInfo/cardRate/productLink}"><img src="images/buy_button.gif" alt="Buy Now" width="65" height="18" border="0" /></a></div>
          <div class="button"><a href="{rates/cardInfo/cardRate/productLink}"><img src="images/info_button.gif" alt="More Info" width="67" height="20" border="0" /></a></div>
     </div>
    </xsl:template>

</xsl:stylesheet>


Any help with this problem would be appreciated!

 
Old March 26th, 2008, 07:53 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

By "the card name" I assume you mean the value of the id attribute of the card you want to process. Then I suspect you want something like this:

<xsl:param name="cardId"/>

<xsl:template match="/">
  <xsl:apply-templates
    select="rates/cardInfo/card[@id=$cardId]"/>
</xsl:template>

<xsl:template match="card">
      <div id="image"><a href="{../cardRate/productLink}">{largeImage}</a></div>
      <div id="rate">
          <div class="name"><xsl:value-of select="@id" /></div>
          <div class="rates"><xsl:value-of select="format-number(../cardRate/localRate, '##.00', 'us')"/>c per minute</div>
          <div class="button"><a href="{../cardRate/productLink}"><img src="images/buy_button.gif" alt="Buy Now" width="65" height="18" border="0" /></a></div>
          <div class="button"><a href="{../cardRate/productLink}"><img src="images/info_button.gif" alt="More Info" width="67" height="20" border="0" /></a></div>
     </div>

Note that the path expressions need to start at the context node - the selected card element.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old March 26th, 2008, 03:06 PM
Registered User
 
Join Date: May 2005
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to Naughtytrini Send a message via Yahoo to Naughtytrini
Default

Thank you...I see where I was going wrong!






Similar Threads
Thread Thread Starter Forum Replies Last Post
Pull and Assign XSLT Parameter from ASPX Doc kwilliams ASP.NET 2.0 Basics 0 October 20th, 2006 11:35 AM
XSLT, add attribute ik XSLT 6 August 22nd, 2006 11:03 AM
xslt for each and attribute tag desse XSLT 1 May 24th, 2006 08:01 AM
changing attribute value in xslt rameshnarayan XSLT 1 August 16th, 2005 08:07 AM
passing attribute info while traversing nodes Ashley XML 1 June 20th, 2003 07:42 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.