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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need help with a transform...

Status
Not open for further replies.

Snaggs

Programmer
Jan 11, 2000
393
US
I have a simple XML file as shown below and a pretty simple XSL transform. I want to color the shipdate different if the status is shipped.

--<report.xml>--
<?xml version=&quot;1.0&quot;?>
<report>
<sale>
<customer>Customer X</customer>
<so>123</so>
<contract>pending</contract>
<stage>Mature</stage>
<shipdate status=&quot;shipped&quot;>08/09/2002</shipdate>
</sale>
<sale>
<customer>Customer A</customer>
<so>123</so>
<contract>pending</contract>
<stage>Mature</stage>
<shipdate status=&quot;ordered&quot;>08/09/2002</shipdate>
</sale>
</report>
--<End Report.xml>--

--<Report.xsl>--
<?xml version=&quot;1.0&quot;?>
<HTML xmlns:xsl=&quot; <BODY STYLE=&quot;font-family:Tahoma; font-size:12pt; background-color:#ffffff&quot;>
<DIV STYLE=&quot;font-weight:bold; font-size=12pt&quot;>
Acme Engineering
</DIV>
<TABLE border=&quot;1&quot; cellspacing=&quot;0&quot;>
<TR>
<TD>Customer</TD>
<TD>Sales Order</TD>
<TD>Contract #</TD>
<TD>Stage</TD>
<TD>Ship Date</TD>
</TR>
<xsl:for-each select=&quot;sale&quot; order-by=&quot;+ customer&quot;>
<TR>
<TD><xsl:value-of select=&quot;customer&quot;/></TD>
<TD><xsl:value-of select=&quot;so&quot;/></TD>
<TD><xsl:value-of select=&quot;contract&quot;/></TD>
<TD><xsl:value-of select=&quot;stage&quot;/></TD>
<xsl:choose>
<xsl:when test=&quot;shipdate/@status='shipped'&quot;>
<TD bgcolor=&quot;#99AAFF&quot;><xsl:value-of select=&quot;shipdate&quot;/></TD>
</xsl:when>
<xsl:eek:therwise>
<TD><xsl:value-of select=&quot;shipdate&quot;/></TD>
</xsl:eek:therwise>
</xsl:choose>
</TR>
</xsl:for-each>
</TABLE>
</BODY>
</HTML>
--<End report.xsl>--

--<ASP Code to generate transform>--
<%@ Language=VBScript %>
<HTML>
<HEAD>
<META NAME=&quot;GENERATOR&quot; Content=&quot;Microsoft Visual Studio 6.0&quot;>
<TITLE>Server-side XML/XSL Merging</TITLE>
</HEAD>
<BODY bgcolor=&quot;#ffffff&quot;>
<%
Dim xmlDoc, xslDoc

Set xmlDoc = Server.CreateObject(&quot;Microsoft.XMLDOM&quot;)
Set xslDoc = Server.CreateObject(&quot;Microsoft.XMLDOM&quot;)

xmlDoc.async = False
xmlDoc.Load(Server.MapPath(&quot;report.xml&quot;))
xslDoc.async = False
xslDoc.Load(Server.MapPath(&quot;report.xsl&quot;))
Response.Write(xmlDoc.documentElement.transformNode(xslDoc.documentElement))

Set xslDoc = Nothing
Set xmlDoc = Nothing
%>
</BODY>
</HTML>
--<End of ASP Code>--

The problem is this line:

<xsl:when test=&quot;shipdate/@status='shipped'&quot;>

It doesn't like comparing the value in the attribute to the value of 'shipped'. If I take out the comparison like this, it will run the transform, but I get the same color for all ship dates.

<xsl:when test=&quot;shipdate/@status&quot;>

So the question is... how do I compare an attribute to a literal to make the transform work?

Thanks in advance,
Snaggs
tribesaddict@swbell.net
Life can only be understood backwards; but it must be lived forwards.
 
To answer my own question... Use this instead:

<xsl:when test=&quot;shipdate[@status='shipped']&quot;> Snaggs
tribesaddict@swbell.net
Life can only be understood backwards; but it must be lived forwards.
 
shona,

You don't really have to specify that the elements are hyperlinks unless you're going to include other types of elements in your xml file. For example.

<web>
<link> <link> <link></web>

...if your xml file looks like that, then I don't see the need to specify that the elements are hyper-links. Or you could do something like this:

<web>
<site>
<name>Tek-Tips</name>
<link> </site>
<site>
<name>Microsoft</name>
<link> </site>
<site>
<name>Oracle</name>
<link> </site>
</web>

Either way the link still can be extracted. If this is not what you're looking for please post more information about what you're trying to do.

Hope that helps Snaggs
tribesaddict@swbell.net
Life can only be understood backwards; but it must be lived forwards.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top