homepage Welcome to WebmasterWorld Guest from 54.166.105.24
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / XML Development
Forum Library, Charter, Moderators: httpwebwitch

XML Development Forum

    
XSL selecting certain values
poisontheused




msg:701928
 1:39 am on Aug 31, 2004 (gmt 0)

I am wanting to change my XSL stylesheet to select all the formattedreportobjects that have a <FormattedReportObject type="CTFormattedField" Type="string" FieldName="{VhStock.MAKE}"> <value> that = Mitsubishi.

At the moment its just outputting all the FormattedReportObjects. Any help would be appreciated.

XML file

<FormattedReportObjects>
<FormattedReportObject type="CTFormattedField" Type="string" FieldName="{VhStock.MAKE}">
<ObjectName>Field81</ObjectName>
<FormattedValue>MITSUBISHI</FormattedValue>
<Value>MITSUBISHI</Value>
</FormattedReportObject>
<FormattedReportObject type="CTFormattedField" Type="string" FieldName="{VhStock.model_name}">
<ObjectName>Field83</ObjectName>
<FormattedValue>MAGNA</FormattedValue>
<Value>MAGNA</Value>
</FormattedReportObject>
</FormattedReportObjects>

<FormattedReportObjects>
<FormattedReportObject type="CTFormattedField" Type="string" FieldName="{VhStock.MAKE}">
<ObjectName>Field81</ObjectName>
<FormattedValue>DAEWOO</FormattedValue>
<Value>DAEWOO</Value>
</FormattedReportObject>
<FormattedReportObject type="CTFormattedField" Type="string" FieldName="{VhStock.model_name}">
<ObjectName>Field83</ObjectName>
<FormattedValue>LANOS</FormattedValue>
<Value>LANOS</Value>
</FormattedReportObject>
</FormattedReportObjects>

Here is my current XSL file

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" xmlns="http://www.w3.org/1999/xhtml">
<xsl:template match="/">
<html>
<basefont face="Verdana" size="2"/>
<body>
<h2>Used Vehicles</h2>
<xsl:apply-templates/>
</body>
</html>
</xsl:template>
<xsl:template match="FormattedReportObjects">

<table border="0">
<xsl:apply-templates/>
</table>

</xsl:template>
<xsl:template match="FormattedReportObject">
<tr>
<xsl:apply-templates select="Value"/>
</tr>
</xsl:template>

<xsl:template match="Value">
<td bgcolor="#E1E1E1" width="200">
<xsl:if test="parent::FormattedReportObject[@FieldName = '{VhStock.MAKE}']">
<xsl:text>Make</xsl:text>
</xsl:if>
<xsl:if test="parent::FormattedReportObject[@FieldName = '{VhStock.model_name}']">
<xsl:text>Model Name</xsl:text>
</xsl:if>
</td>

<td>
<xsl:value-of select="text()"/>
</td>
</xsl:template>
</xsl:stylesheet>

Thanks for your time

 

TravelSite




msg:701929
 3:42 pm on Sep 7, 2004 (gmt 0)

poisontheused,
I'm new to xml - so there may be a different method than this!

If I need to select xml elements that contain a particular value I use a "Choose" tag. Below is a sample doc:

<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xsl" href="people.xsl"?>
<people>
<person>
<id>1</id>
<firstname>John</firstname>
<surname>Smith</surname>
<age>27</age>
</person>
<person>
<id>2</id>
<firstname>Joe</firstname>
<surname>Blogs</surname>
<age>19</age>
</person>
<person>
<id>3</id>
<firstname>Peter</firstname>
<surname>Smith</surname>
<age>27</age>
</person>
<person>
<id>4</id>
<firstname>Tom</firstname>
<surname>Blogs</surname>
<age>19</age>
</person>
</people>

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<h2>Family</h2>
<table border="1">
<tr bgcolor="#9acd32">
<th align="left">Firstname</th>
<th align="left">Surname</th>
</tr>
<xsl:for-each select="people/person">
<xsl:choose>
<xsl:when test="surname='Smith'">
<tr>
<td><xsl:value-of select="firstname"/></td>
<td><xsl:value-of select="surname"/></td>
</tr>
</xsl:when>
</xsl:choose>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>

The "for-each" tag selects all the elements, but the "choose" tag narrows it down to those elements that meet the conditions in its "test" attribute - i.e. surname='Smith'. Note that "test" is part of the tag.

Theres also an optional "<otherwise>" tag associated with the <choose> tag (search for "xml choose when otherwise tutorial" on Google for more info)

Hope this helps.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / XML Development
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved