|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
XML file
Code:
<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>
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. Here is my current XSL file Code:
<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 |
|
#2
|
|||
|
|||
|
Can you check this line,
<FormattedReportObject type="CTFormattedField" Type="string" FieldName="{VhStock.MAKE}"> Can you do that? I think it may be possible to only have one value in there. Only type for example. You can do it like this though, <FormattedReportObject> <type>CTFormattedField</type> <Type>string</Type> <FieldName>{VhStock.MAKE}</FieldName> </FormattedReportObject> I am not sure what you are trying with the {} value either. But to keep it simple try it with an actual value first. Try and do it as simply as possible first, take out the last 2 templates and just do it in the first one. The templates look a bit wrong at the moment to me. I don't think you need the third one, but avoid all that at first and get it working. |
|
#3
|
|||
|
|||
|
The XML file is generated in that syntax from Crystal reports. It is a very long XML file that is going to need regular updating so rewriting the XML file is not really an easy solution unfortunately.
Its quite an awkward setup i know, and thats why it's causing me some trouble trying to get it to select certain values. I think i need to use XSL:if or XSL:choose but am unsure how to write this with my particular XML file. |
|
#4
|
|||
|
|||
|
Check out this page and it might shed some light on why I brought up your xml,
http://www.w3schools.com/xml/xml_attributes.asp As regards <xsl:if> and <xsl:choose>, well you'd use <xsl:choose> if you are looking for one value and if not that value then another one (hence <xsl therwise>). If you are only looking for one particular value then use xsl:if.I think you need to use xsl:if something like this, <xsl:if test="First Node"> <xsl:if test="Second Node"> <xsl:if test="Third Node"> Do something here... </xsl:if> </xsl:if> </xsl:if> This won't do anything unless you have all the nodes matching what you want. There may be a better way of doing this but for the time being, try and get a simple working xsl file first and take it from there. |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > XML Programming > XSL:if or XSL:choose help |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|