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
Variables 如何使用参数或变量值作为节点名称?_Variables_Xslt_Parameters - Fatal编程技术网

Variables 如何使用参数或变量值作为节点名称?

Variables 如何使用参数或变量值作为节点名称?,variables,xslt,parameters,Variables,Xslt,Parameters,我试图将参数或变量的值用作select值内的节点名称,但迄今为止失败 因此,我的XML如下所示 <Data> <Name>John Smith</Name> <Date>28112012</Date> <Phone>iphone</Phone> <Car>BMW</Car> </Data> 约翰·史密斯 28112012 苹果手机 宝马 我不完整的xslt如下所示

我试图将参数或变量的值用作select值内的节点名称,但迄今为止失败

因此,我的XML如下所示

<Data>
 <Name>John Smith</Name>
 <Date>28112012</Date>
 <Phone>iphone</Phone>
 <Car>BMW</Car>
</Data>

约翰·史密斯
28112012
苹果手机
宝马
我不完整的xslt如下所示

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
    version="2.0"
    exclude-result-prefixes="#all">

<xsl:param name="nodename" select="'Name'"/>

<xsl:template match="/Data">

      <Output>
        <xsl:value-of select="{$nodename}"/>
      </Output>     
</xsl:template>

</xsl:stylesheet>

理想情况下,我想把它放出来

<Output>John Smith</Output>
约翰·史密斯 使用XSLT有什么方法可以做到这一点吗? 我希望能够根据用户的选择选择适当的节点

谢谢


SK

胡乱猜测,让我知道它是否有效:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0" exclude-result-prefixes="#all">

<xsl:param name="nodename" select="'Name'"/>
<xsl:template match="/Data">
   <Output>
      <xsl:value-of select="//*[name()=$nodename]" />
   </Output>     
</xsl:template>

</xsl:stylesheet>