Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Getting First Element. 2

Status
Not open for further replies.

Karl Blessing

Programmer
Feb 25, 2000
2,936
US
I have a price dropdown list. As shown in the Partial XML here

Code:
<galleries>
	<gallery id="bees">
		<image name="crw_0640" convertable="yes">
			<longname>Bee on Yellow Flower</longname>
			<description>A honey bee on top of a yellow flower. Grass out of focus in background.</description>
			<price>125.00</price>
			<prints>
				<print name="Electronic File" price="125.00" />
				<print name="3.5x5" price="5.00" />
				<print name="4 x 6" price="7.00" />
				<print name="5 x 7" price="10.00" />
				<print name="8 x10" price="20.00" />
				<print name="8 x12" price="25.00" />
				<print name="11x14" price="35.00" />
				<print name="16x20" price="45.00" />
			</prints>
			<dimension>3076x2052 pixels (10.2 x 6.8 inches @ 300 DPI)</dimension>
			<format>8-bit LZW TIFF</format>
		</image>
....
</gallery>
</galleries>

I have this portion of the XSL that I wish to change.

Code:
<xsl:template match="prints">
	<select name="prints" onchange="setprice(this.options[this.options.selectedIndex].value);">
		<xsl:apply-templates select="print" />
	</select> 
</xsl:template>

<xsl:template match="print">
	<option><xsl:attribute name="value"><xsl:value-of select="../../longname"/>:<xsl:value-of select="./@name"/>-<xsl:value-of select="./@price"/></xsl:attribute>
	<xsl:value-of select="./@name"/> - <xsl:value-of select="./@price"/> USD
	</option>
</xsl:template>

<xsl:template match="image">
	<xsl:if test="$image = ./@name">
	<table border="0" width="100%" cellpadding="0" cellspacing="0" align="center">
		<tr>
			<td>									
				<div style="border:1px solid #000000;padding:0px;background:#606B73;">
					<table border="0" cellspacing="0" cellpadding="2" width="100%" style="background:#333A40;color:#FFFFFF;">
						<tr>
							<td class="bodysubhead">
								Purchase Information
							</td>
							<td align="right" class="bodysubhead">
								[<a id="purchase_link" onclick="toggle(this, 'purchase');"  title="show/hide" href="javascript: void(0);"  style="text-decoration:none;color:#FFFFFF;">Close</a>]
							</td>
						</tr>
					</table>
					<div id="purchase" style="padding:0px;">
		<p class='para'>
		<b>ID:</b><xsl:text>  </xsl:text><xsl:value-of select="./@name"/><BR/>
		<b>Name:</b><xsl:text>  </xsl:text><xsl:value-of select="./longname"/><BR/>
		<b>Description:</b><xsl:text>  </xsl:text><xsl:value-of select="./description"/><BR/>
		<b>Dimension:</b><xsl:text>  </xsl:text><xsl:value-of select="./dimension"/><BR/>
		<b>Format:</b><xsl:text>  </xsl:text><xsl:value-of select="./format"/><BR/>
		<xsl:apply-templates select="prints" />
		</p>
		<form target="paypal" name="paypal" id="paypal" action="[URL unfurl="true"]https://www.paypal.com/cgi-bin/webscr"[/URL] method="post">
			<input type="image" src="[URL unfurl="true"]https://www.paypal.com/en_US/i/btn/x-click-but22.gif"[/URL] name="submit" title="Make payments with PayPal - it's fast, free and secure!" alt="Make payments with PayPal - it's fast, free and secure!"/>
			<input type="hidden" name="add" value="1"/>
			<input type="hidden" name="cmd" value="_cart"/>
			<input type="hidden" name="business">
				<xsl:attribute name="value"><xsl:value-of select="$account"/></xsl:attribute>
			</input>
			[b]<input type="hidden" name="item_name">
				<xsl:attribute name="value"><xsl:value-of select="./longname"/><xsl:text>:Electronic File</xsl:text></xsl:attribute>[/b]
			</input>
			<input type="hidden" name="item_number">
				<xsl:attribute name="value"><xsl:value-of select="./@name"/></xsl:attribute>
			</input>
			[b]<input type="hidden" name="amount" >
				<xsl:attribute name="value"><xsl:value-of select="./price"/></xsl:attribute>
			</input>[/b]
			<input type="hidden" name="no_note" value="1"/>
			<input type="hidden" name="currency_code" value="USD"/>
			<input type="hidden" name="lc" value="US"/>
		</form>
		<xsl:if test="./@convertable = 'yes'">
			<i>This file may be converted to another format upon request in order form</i><BR/>
		</xsl:if>
		<a href="/-legal/">License Agreement for Purchased Photographs</a>
						
					</div>
				</div>
			</td>
		</tr>
	</table>
	<script language="javascript" type="text/javascript">toggle(getObject('purchase_link'), 'purchase');</script>		
	</xsl:if>
</xsl:template>

the bolded areas is where I'd like to fill with the first element of the prints list, rather than having to pull from a seperate price tag as a default.

How can I basically go down into the child of a current area, and pull the first price/name out of two tags down in a way.

Karl Blessing
PHP/MySQL Developer
 
Not entirely sure what you are trying to achieve, but to select the price attribute of the 3rd print element, for example, you'd do this:

Code:
<xsl:value-of select="prints/print[position()=3]/@price" />
 
ok, so 1 would be the first one, thats basically what i'm trying to do is , make the paypal form, use the first entry , as the default values.

Karl Blessing
PHP/MySQL Developer
 
Works I just did this

Code:
		<form target="paypal" name="paypal" id="paypal" action="[URL unfurl="true"]https://www.paypal.com/cgi-bin/webscr"[/URL] method="post">
			<input type="image" src="[URL unfurl="true"]https://www.paypal.com/en_US/i/btn/x-click-but22.gif"[/URL] name="submit" title="Make payments with PayPal - it's fast, free and secure!" alt="Make payments with PayPal - it's fast, free and secure!"/>
			<input type="hidden" name="add" value="1"/>
			<input type="hidden" name="cmd" value="_cart"/>
			<input type="hidden" name="business">
				<xsl:attribute name="value"><xsl:value-of select="$account"/></xsl:attribute>
			</input>
			<input type="hidden" name="item_name">
				[b]<xsl:attribute name="value"><xsl:value-of select="./longname"/>:<xsl:value-of select="./prints/print[position()=1]/@name"/></xsl:attribute>[/b]
			</input>
			<input type="hidden" name="item_number">
				<xsl:attribute name="value"><xsl:value-of select="./@name"/></xsl:attribute>
			</input>
			<input type="hidden" name="amount" >
				[b]<xsl:attribute name="value"><xsl:value-of select="./prints/print[position()=1]/@price"/></xsl:attribute>[/b]
			</input>
			<input type="hidden" name="no_note" value="1"/>
			<input type="hidden" name="currency_code" value="USD"/>
			<input type="hidden" name="lc" value="US"/>
		</form>

Thanks.

Karl Blessing
PHP/MySQL Developer
 
XSL will select the first node in a node list by default. So just putting ./prints/print/@name will do the same thing.
 
also...
You can just use [1] in place of [position()=1]

Visit My Site
PROGRAMMER: (n) Red-eyed, mumbling mammal capable of conversing with inanimate objects.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top