XML Transformation

User avatar
Jezza
5StarLounger
Posts: 847
Joined: 24 Jan 2010, 06:35
Location: A Magic Forest in Deepest, Darkest, Kent

XML Transformation

Post by Jezza »

I have the following XML sample

Code: Select all

<GetSchedulesResult>
	<Items>
		<Item>
			<Ref>1147</Ref>
			<Desc>Magic Forest Delivery</Desc>
			<Date>10/02/2010</Date>
			<Day>WEDNESDAY</Day>
			<SlotsMax>35</SlotsMax>
			<SlotsTaken>0</SlotsTaken>
			<SlotsAvail>35</SlotsAvail>
		</Item>
	</Items>
</GetSchedulesResult>
That I am using XLST to transform with the addition of a radio button set to allow me to make a selection from an extended XML set. The code below allows me to select a node and return the Ref (1147) which I extract and snd to my application HTML layer. Due to the complexity of the system ( it is not bespoke but a product) I am only able to work in a define way as I am customising certain aspects of it for an integration.

What I would like it to do is return both the Ref and Date from the set when I click the option, any ideas on how I could adjust my XSL to extract this value as well

Code: Select all

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" omit-xml-declaration="yes" indent="yes"/>
<xsl:param name="Services"/>
<xsl:param name="responseCode"/>
<xsl:template match="/">
<table border="0" cellspacing="0" style="width:75%" align="center">
<tr class="columnheader">
	<td align="center">Select</td>
	<td align="center">Ref.</td>
	<td align="center">Day</td>
	<td align="center">Date</td>
	<td align="center">Slots Available</td>
</tr>

<xsl:for-each select="//Item">
<tr class="row{position() mod 2 + 1}">
<td align="center"><input type="radio">
  <xsl:attribute name="name">primary_Id</xsl:attribute> 
  <xsl:attribute name="id">primary_Id</xsl:attribute> 
 <xsl:attribute name="value"><xsl:value-of select="Ref" /></xsl:attribute>
 <xsl:attribute name="realValue"><xsl:value-of select="Date" /></xsl:attribute>
  <xsl:attribute name="hasAdditionalText">0</xsl:attribute> 
 <xsl:if test="$responseCode=Service">
  <xsl:attribute name="checked">1</xsl:attribute> 
  </xsl:if>
  </input></td>

	<td align="center"><xsl:value-of select="Ref" /></td>
	<td align="center"><xsl:value-of select="Day"/></td>
	<td align="center"><xsl:value-of select="Date" /></td>
	<td align="center"><xsl:value-of select="SlotsAvail"/></td>


</tr>
</xsl:for-each>
</table>
</xsl:template>
</xsl:stylesheet>
Jerry
I’ll be more enthusiastic about encouraging thinking outside the box when there’s evidence of any thinking going on inside it

User avatar
Jezza
5StarLounger
Posts: 847
Joined: 24 Jan 2010, 06:35
Location: A Magic Forest in Deepest, Darkest, Kent

Re: XML Transformation

Post by Jezza »

Sorted

Code: Select all

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" omit-xml-declaration="yes" indent="yes"/>
<xsl:param name="Services"/>
<xsl:param name="responseCode"/>
<xsl:template match="/">
<table border="0" cellspacing="0" style="width:75%" align="center">
<tr class="columnheader">
	<td align="center">Select</td>
	<td align="center">Ref.</td>
	<td align="center">Day</td>
	<td align="center">Date</td>
	<td align="center">Slots Available</td>
</tr>

<xsl:for-each select="//Item">
<tr class="row{position() mod 2 + 1}">
<td align="center"><input type="radio">
  <xsl:attribute name="name">primary_Id</xsl:attribute> 
  <xsl:attribute name="id">primary_Id</xsl:attribute> 
 <xsl:attribute name="value">Ref:<xsl:value-of select="Ref" />_Date:<xsl:value-of select="Date" /></xsl:attribute>
 <xsl:attribute name="realValue"><xsl:value-of select="Date" /></xsl:attribute>
  <xsl:attribute name="hasAdditionalText">0</xsl:attribute> 
 <xsl:if test="$responseCode=Service">
  <xsl:attribute name="checked">1</xsl:attribute> 
  </xsl:if>
  </input></td>

	<td align="center"><xsl:value-of select="Ref" /></td>
	<td align="center"><xsl:value-of select="Day"/></td>
	<td align="center"><xsl:value-of select="Date" /></td>
	<td align="center"><xsl:value-of select="SlotsAvail"/></td>


</tr>
</xsl:for-each>
</table>
</xsl:template>
</xsl:stylesheet>
I added this line

Code: Select all

<xsl:attribute name="value">Ref:<xsl:value-of select="Ref" />_Date:<xsl:value-of select="Date" /></xsl:attribute>
Last edited by HansV on 05 Feb 2010, 22:12, edited 1 time in total.
Reason: to enable BBCode
Jerry
I’ll be more enthusiastic about encouraging thinking outside the box when there’s evidence of any thinking going on inside it