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

Puting a link value? 1

Status
Not open for further replies.

mike314

Programmer
Jun 24, 2003
143
US
Quick one here, I have these xsl variables set up, but they are not being displayed in the HTML:

<xsl:variable name="type" select="arf"/>
<xsl:variable name="altType" select="dgh"/>
<xsl:variable name="iconSrc" select="link"/>

<img src="{$iconSrc}" alt="{$altType}" width="12" height="14" border="0" align="absmiddle"/>&nbsp;<span class="nav"><xsl:value-of select="$type"/></span><a href="{$link}" class="linksmall">This is a link</a><br/>


Is there a way to put these xsl values in this HTML line? It has to be in xsl variables because the value changes depending on page.

thanks
 
What does the xml look like?

I imagine you need some path to the elements, such as:
Code:
<xsl:variable name="type" select="/arf"/>
<xsl:variable name="altType" select="/dgh"/>
<xsl:variable name="iconSrc" select="/link"/>
Or
Code:
<xsl:variable name="type" select="//arf"/>
<xsl:variable name="altType" select="//dgh"/>
<xsl:variable name="iconSrc" select="//link"/>

Then you could also use:
Code:
<img src="{/link}" alt="{/dgh}" width="12" height="14" border="0" align="absmiddle"/>&nbsp;<span class="nav"><xsl:value-of select="/arf"/></span><a href="{/link}" class="linksmall">This is a link</a><br/>
Without the variables, depending on the structure of you XSL & XML

Visit My Site
PROGRAMMER: (n) Red-eyed, mumbling mammal capable of conversing with inanimate objects.
 
no, I want to give it those values or is that not possible?

for example:
<xsl:variable name="type" select="arf"/>
<xsl:variable name="altType" select="/dgh"/>
<xsl:variable name="iconSrc" select="/link"/>

for type I want the value to be arf
 
why are you setting the variable for type to "arf" in the XSL, that is pointless...

You might as well just put "arf" in the target tag...

For the variable to have any benifit, you would want to place the value in an xml tag, then read it into a variable in XSL. Otherwise, it is static in the XSL file, and takes away from the purpose of the variable.

Again, with XML, it's hard to understand what you are trying to do, without seeing the XML you are working with...

Due to the nature of XML, as being a "Define Your Own Structure" luanguage, there are many possible senarios that your question could fall into, all having different results...

If you can post the XML, we can get your question answered much faster...

Visit My Site
PROGRAMMER: (n) Red-eyed, mumbling mammal capable of conversing with inanimate objects.
 
I see what your saying, but basically its set up like that because I plan on putting this in a xsl:when test structure and depending on the when test I want the variable to reflect that selection.

but the problem I am having is just to get the values of those variables type, iconSrc, and altType into the HTML.

Example:

<xsl:when test="$total = '12'">
<xsl:variable name = type select="arf"/>
</xsl:when>

and basically put $type into the HTML, but from what I have above in the HTML, it doesn't work. There will be more when test cases, thats just a small example.

Can you see my error, if there is one
thanks
 
OK...
That makes more sense...
You need to flip the order of the tags...
XSL can get a little tricky when it comes to this...

In this case, you have the variable inside the when statement... XSL sees the variable as being a temporary variable for use within the <when> tag

Use this as an example:
Code:
<1>
  <2>
    <4>
      <7>test1</7>
    </4>
    <5>
      <8>test2</8>
    </5>
  </2>
  <3>
    <6>test3</6>
  </3>
</1>

tag <8> can see tags <4>, <2>, & <1>, but it can't see <7> because it is on a seperate branch...

However, the you could make <4> inherit the value of <7>, then <8> can see <4> which is the value of <7>

But for <6> to see either <7> or <8>, <2> would have to be evaluated to either of the 2 (<7> or <8>)

Confused?

The trick is to make the <variable> the parent and the <when> the child, rather than vice versa...

If <when> is the parent of <variable>, then <variable> can only be used within <when>

On the other hand, <if> can return a value to it's parent, so if <variable> is the parent, it will inherit the result of <when>

*Note:
<if> & <when> are both conditional statements that return values, for the above reference you can use <when> & <if> interchangeably...


so do this instead...
Code:
[b]<xsl:variable name="type">[/b]
  <xsl:choose>
    [b]<xsl:when test="$total = '12'">arf</xsl:when>[/b]
    <xsl:otherwise></xsl:otherwise>
  </xsl:choose>
</xsl:variable>
And it should work fine...

*Note: <xsl:when> is used inside <xsl:choose> along with <xsl:eek:therwise>
if you don't need multiple conditions, use <xsl:if> in place of <xsl:when> without the <xsl:choose> tag

Feel free to ask any questions about the above explaination...
Like I said, it CAN get tricky ;-)

Hope this Helps,
-Josh

Visit My Site
PROGRAMMER: (n) Red-eyed, mumbling mammal capable of conversing with inanimate objects.
 
BTW...

the <if> version would look like:
Code:
<xsl:variable name="type">
  <[b]xsl:if[/b] test="$total = '12'">arf<[b]/xsl:if[/b]>
</xsl:variable>

Visit My Site
PROGRAMMER: (n) Red-eyed, mumbling mammal capable of conversing with inanimate objects.
 
or going back to the beginning:

<xsl:variable name="type" select="'arf'"/>
<xsl:variable name="altType" select="'dgh'"/>
<xsl:variable name="iconSrc" select="'link'"/>
 
ok thanks!! I see it now. What I was doing was making the variable, the child and therefore it will never reach its desired goal.

thanks a million!!!!!!!
 
No problem... (thanks for the star)
Sounds like you got!!!
Good Luck ;-)

Visit My Site
PROGRAMMER: (n) Red-eyed, mumbling mammal capable of conversing with inanimate objects.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top