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

XSLT logic needed 1

Status
Not open for further replies.

LOW

Programmer
Sep 27, 2000
45
0
0
US
I'm trying to add a little more logic to the following template named "drawcell" specifically to the param "linkfield" (top section of code). If a particular field DOCUMENT_URL contains "pubtest" in the url, I'd like the value to be <xsl:value-of select="MT[@N='DOCUMENT_URL']/@V"/> rather than "U", otherwise the value continues to be "U". I'm just not sure how to accomplish that as I'm quite new to XSLT.

Here's the piece of my code, I'm attempting to edit:

<xsl:template name="drawcell_alt">
<xsl:param name="meta"/>
<xsl:param name="linkfield"/>
<td valign="top">
<xsl:if test="$linkfield=$meta">
<xsl:text disable-output-escaping="yes">
&lt;a href="</xsl:text><xsl:value-of select="U"/> <xsl:text disable-output-escaping="yes">"&gt;</xsl:text>
</xsl:if>

Lots of other code goes here. I'm not including as it's not pertinent.

<xsl:if test="$linkfield=$meta">
<xsl:text disable-output-escaping="yes">&lt;/a&gt;</xsl:text>
</xsl:if>
</td>
 
[1] What is then DOCUMENT_URL? you said it is a "particular field".
>If a particular field DOCUMENT_URL contains "pubtest" in the url, I'd like the value to be <xsl:value-of select="MT[@N='DOCUMENT_URL']/@V"/> rather than "U", otherwise the value continues to be "U".
In that case what is
> select="MT[@N='DOCUMENT_URL']/@V"
going to be? The above line mean @N equal to the literal string 'DOCUMENT_URL'. That is contradictory and it cannot be right.

[2] Whatever it means, I take the line in its figurative sense herein-below. You have to make the corresponding adjustment.

[2.1] The way you make the anchor link is no good. It is constructed as any other tags. Why would you make xsl:text with disable-output-escaping? There is absolutely no need and it obscurs the whole script.

[2.2] You can do it like this.
[tt]
<td valign="top">
<xsl:if test="$linkfield=$meta">
<a>
<xsl:attribute name="href">
<xsl:choose>
<xsl:when test="contains(DOCUMENT_URL, 'pubtest')">
<xsl:value-of select="MT[@N=normalize-space(DOCUMENT_URL)]/@V" />
<xsl:eek:therwise>
<xsl:value-of select="U"/>
</xsl:eek:therwise>
</xsl:choose>
</xsl:attribute>
<!-- Lots of other code goes here. I'm not including as it's not pertinent. -->
</a>
</xsl:if>
</td>
[/tt]
 
Amendment
Upon reading what I posted, I find out that I missed out closing tag of xsl:when. Should obviously add it back if you use it for testing or else.
 
Thank you, you've been very helpful. DOCUMENT_URL is the name of a field within a database. Below is the code with a slight modification when referencing DOCUMENT_URL. I'm still struggling with the syntax. When the DOCUMENT_URL field contains "pubtest" within the field, then the href to equal the value of what is in the DOCUMENT_URL field. Below is the code I'm testing with (still not getting the expected result though).

<td valign="top">
<xsl:if test="$linkfield=$meta">
<a>
<xsl:attribute name="href">
<xsl:choose>
<xsl:when test="MT@N='DOCUMENT_URL']/@value='pubtest'">
<xsl:value-of select="MT[@N=normalize-space(DOCUMENT_URL)]/@V" />
</xsl:when>
<xsl:eek:therwise>
<xsl:value-of select="U"/>
</xsl:eek:therwise>
</xsl:choose>
</xsl:attribute>
</a>
 
[3] If DOCUMENT_URL is the column name of some database at certain row (according to the context of the node under which the xsl part is executing) then you have to rely on extension of xslt "pure"! Xslt itself wouldn't know how to interact with external dbase.

[3.1] If DOCUMENT_URL is known at that stage and is fed into the xslt as variable (with a name like DOCUMENT_URL, for instance), you can use it as $DOCUMENT_URL in the xsl:when part etc... just like you use $meta or $linkfield, so I can suppose you understand the how-to. Otherwise, there is no proxy for something like rs('DOCUMENT_URL').value in xslt, no.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top