2012-05-01 10 views
60
<a> 
    <xsl:attribute name="href"> 
    <xsl:value-of select="/*/properties/property[@name='report']/@value" /> 
    </xsl:attribute> 
</a>  

¿Hay alguna manera de cancat otra cadena aCómo concat una cadena a xsl: value-of select =" ...

<xsl:value-of select="/*/properties/property[@name='report']/@value" /> 

que necesito para pasar un poco de texto a atributo href en Además del valor de la propiedad informe

Respuesta

103

Usted puede utilizar la función XPath en lugar sensiblemente nombre denominada concat aquí

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

Por supuesto, no tiene que ser texto aquí, puede ser otra expresión xpath para seleccionar un elemento o atributo. Y puede tener cualquier número de argumentos en la expresión concat.

hacer la nota, se puede hacer uso de plantillas de valor de atributo (representados por las llaves) para simplificar su expresión

<a href="{concat('myText:', /*/properties/property[@name='report']/@value)}"></a> 
+2

@TimC: Bueno, pero el 'concat() función' no es necesario en este caso. –

+0

Tengo la siguiente etiqueta: 'Anders, John' y me gustaría crear un campo oculto en XSLT que solo toma el ID #. ¿Cómo puedo lograr eso? – SearchForKnowledge

14

Uso:

<a href="wantedText{/*/properties/property[@name='report']/@value)}"></a> 
17

tres respuestas:

Simple:

<img> 
    <xsl:attribute name="src"> 
     <xsl:value-of select="//your/xquery/path"/> 
     <xsl:value-of select="'vmLogo.gif'"/> 
    </xsl:attribute> 
</img> 

El uso de 'concat':

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

Atributo de acceso directo como sugiere @TimC

<img src="{concat(//your/xquery/path,'vmLogo.gif')}" /> 
+1

Según lo observado por Dimitre, no necesita el concat aquí: '' – Svish

3

La forma más fácil de concat una cadena de texto estático a un valor seleccionado es utilizar elemento.

<a> 
    <xsl:attribute name="href"> 
    <xsl:value-of select="/*/properties/property[@name='report']/@value" /> 
    <xsl:text>staticIconExample.png</xsl:text> 
    </xsl:attribute> 
</a> 
-1

método más fácil es

<TD> 
    <xsl:value-of select="concat(//author/first-name,' ',//author/last-name)"/> 
    </TD> 

cuando la estructura XML es

<title>The Confidence Man</title> 
<author> 
    <first-name>Herman</first-name> 
    <last-name>Melville</last-name> 
</author> 
<price>11.99</price> 
Cuestiones relacionadas