如何将字符串连接到xsl:value-of select ="...?

Han*_*nth 88 xslt xpath

<a>
    <xsl:attribute name="href"> 
     <xsl:value-of select="/*/properties/property[@name='report']/@value" />
    </xsl:attribute>
</a>    
Run Code Online (Sandbox Code Playgroud)

是否有任何方法可以将另一个字符串添加到

<xsl:value-of select="/*/properties/property[@name='report']/@value"  />
Run Code Online (Sandbox Code Playgroud)

除了报告属性值之外,我还需要将一些文本传递给href属性

Tim*_*m C 139

你可以在这里使用名为concat的相当明智的命名xpath函数

<a>
   <xsl:attribute name="href">
      <xsl:value-of select="concat('myText:', /*/properties/property[@name='report']/@value)" />
   </xsl:attribute>
</a>  
Run Code Online (Sandbox Code Playgroud)

当然,它不必是文本,它可以是另一个选择元素或属性的xpath表达式.并且你可以在concat表达式中包含任意数量的参数.

请注意,您可以在此处使用属性值模板(由花括号表示)来简化表达式

<a href="{concat('myText:', /*/properties/property[@name='report']/@value)}"></a>
Run Code Online (Sandbox Code Playgroud)

  • @TimC:很好,但这里不需要`concat()`函数. (2认同)

Nin*_*oel 26

三个答案:

简单:

<img>
    <xsl:attribute name="src">
        <xsl:value-of select="//your/xquery/path"/>
        <xsl:value-of select="'vmLogo.gif'"/>
    </xsl:attribute>
</img>
Run Code Online (Sandbox Code Playgroud)

使用'concat':

<img>
    <xsl:attribute name="src">
        <xsl:value-of select="concat(//your/xquery/path,'vmLogo.gif')"/>                    
    </xsl:attribute>
</img>
Run Code Online (Sandbox Code Playgroud)

@TimC建议的属性快捷方式

<img src="{concat(//your/xquery/path,'vmLogo.gif')}" />
Run Code Online (Sandbox Code Playgroud)

  • 正如Dimitre所指出的,您无需在此处进行连接:`&lt;img src =“ {// your / xpath} vmLogo.gif” /&gt;` (2认同)

Dim*_*hev 16

用途:

<a href="wantedText{/*/properties/property[@name='report']/@value)}"></a>
Run Code Online (Sandbox Code Playgroud)


Dav*_*now 5

将静态文本字符串连接到选定值的最简单方法是使用 元件.

<a>
  <xsl:attribute name="href"> 
    <xsl:value-of select="/*/properties/property[@name='report']/@value" />
    <xsl:text>staticIconExample.png</xsl:text>
  </xsl:attribute>
</a>
Run Code Online (Sandbox Code Playgroud)