Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xml 连接中的XSLT多个变量未传播_Xml_Variables_Xslt - Fatal编程技术网

Xml 连接中的XSLT多个变量未传播

Xml 连接中的XSLT多个变量未传播,xml,variables,xslt,Xml,Variables,Xslt,我定义的变量是作为字符串传递的,而不是传播值 来源 <?xml version="1.0"?> <results> <result> <title_id> 123456 </title_id> <product_id> 2 </product_id> <track_id&g

我定义的变量是作为字符串传递的,而不是传播值

来源

<?xml version="1.0"?>
<results>
    <result>
        <title_id>
            123456
        </title_id>
        <product_id>
            2
        </product_id>
        <track_id>
            5
        </track_id>
    </result>
</results>

123456
2.
5.
XSL


链接

输出:
http://www.myaddress/$titlevar-$productvar/?$trackvar
我想要的是:
http://www.myaddress/123456-5/?2
。我试过各种括号、撇号和语言标记。有人知道它为什么不工作吗?

变量引用周围不应该有引号。还要注意使用
normalize-space()

这项工作:

<html xsl:version="1.0"
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
      xmlns="http://www.w3.org/1999/xhtml">

  <body>
    <table border="1" cellpadding="4" cellspacing="0">
      <tr bgcolor="#fb0006" align="center">
    <td><b>Link</b></td>
      </tr>

      <xsl:for-each select="//results/result">

    <xsl:variable name="titlevar" select="normalize-space(title_id)" />
    <xsl:variable name="productvar" select="normalize-space(product_id)" />
    <xsl:variable name="trackvar" select="normalize-space(track_id)" />

    <tr>
      <td><a href="{concat('http://www.myaddress/', 
                    $titlevar, '-', $productvar, '/?', $trackvar)}" 
             target="_blank">link</a></td>
    </tr>

      </xsl:for-each>

    </table>
  </body>
</html>

链接

您需要删除变量周围的引号:

<tr>
 <td><a href="{concat('http://www.myaddress/', $titlevar, 
                      '-', $productvar, '/?', $trackvar)}" 
        target="_blank">link</a></td>
</tr>

<tr>
 <td><a href="{concat('http://www.myaddress/', $titlevar, 
                      '-', $productvar, '/?', $trackvar)}" 
        target="_blank">link</a></td>
</tr>