Search code examples
htmlxslthref

XSLT concat with <value-of> and text Href


I'm trying to concatenate some text and values into a Href.

Basically i need to concatenate this :

String with part of the link: http://server/area/graphic.aspx?ns=

After the ns= i need to use <xsl:value-of select="number">

Then add &nocache=5555

and concat all this values to create this

'http://server/area/graphic.aspx?ns=9999&nocache=5555'

Then put this in a Href to use it as an image.

i've tried some stuff but nothing seems to work ..

Thanks

EDIT: ok most of the stuff i tried just comepletly failed, but i got this , this is the closest i got to getting it right

<xsl:template match="MODULO[NAME='Identity']" name="Tmp_Identificacao">
    <img>
    <xsl:attribute name="src">
        http://server/area/graphic.aspx?ns=<xsl:value-of 
        select="substring-before(VALUES/ROW/number,'-')"/>&#160;nocache=5555
    </xsl:attribute>
    </img>
</template>

 <MODULO>
    <NAME>ObtemIdentificacao_P</NAME>
    <VALUES>
      <ROW>
        <number>9999</number>
     </ROW>
   <VALUES>
<MODULO>

The code runs , and it show's everything it needs , besides the image , I've tried inspecting the element and came up whit something , the src of the image doesn't show the value of the VALUES/ROW/number and it doesn't show the & before nocache like this

<img src="http://server/area/graphic.aspx?ns= nocache=5555">

only thing i need to get this working is to put the value of the number and the & before nocache Other than this i don't know what i can show , thanks in advance

PS:this is part of a big XSLT file , there's is nothing wrong with code beside this image im trying to implement.


Solution

  • If you don't mind to have the & escaped as &amp; in the URL you can use this XML:

    <img href="{concat('http://server/area/graphic.aspx?ns=', number, '&amp;nocache=5555')}" />
    

    Output: (current node = ROW)

    <img href="http://server/area/graphic.aspx?ns=9999&amp;nocache=5555"/>