2012-02-06 4 views
0

출력 문서 내에서 루트 태그 아래에있는 노드 a에 값 "a"를 가져 오려고합니다 (입력은 모두 가능). 나는 그것이하는 경우에 그것을 알고있다동적 변수에서 노드 채우기

<xsl:value-of select="$item1"/> 

나는 얻는다. 그러나 나는 동적으로 많은 변수를 생성 할 수 있기 때문에 그 이유는

<xsl:value-of select="concat('$item','1')"/> 

같은 것을 사용하려면, 변수의 끝에있는 숫자가 증가됩니다. 그래서 item1, item2, item3 등을 가질 수 있습니다. 여기서는 샘플을 보여주었습니다. 그래서 select 값에 하드 코딩 된 값 '1'을 사용하는 것입니다. xslt1.0에서 가능합니까? 여기

가변 변수/XPath는 XSLT 1.0 1.0 불가능 같은 모든 입력 XML이

<?xml version="1.0" encoding="utf-8"?> 
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
    xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl" 
> 
    <xsl:output method="xml" indent="yes"/> 

    <xsl:template match="/"> 
     <xsl:variable name="item1" select="'a'" /> 
     <Root> 
     <a> 
      <xsl:value-of select="concat('$item','1')"/> 
     </a> 
     </Root> 
    </xsl:template> 
</xsl:stylesheet> 

답변

1

PHP 사용될 수 XSLT 내이다.

exslt 확장의 node-set() 기능을 사용하면 배열처럼 작동하는 노드 집합을 구축 할 수 있습니다.

<?xml version='1.0' encoding='UTF-8'?> 
<xsl:stylesheet version='1.0' 
       xmlns:xsl='http://www.w3.org/1999/XSL/Transform' 
       xmlns:exsl='http://exslt.org/common' 
       xmlns:msxsl='urn:schemas-microsoft-com:xslt' 
       exclude-result-prefixes='msxsl exsl'> 

<xsl:template match='/'> 
    <!-- result tree fragment --> 
    <xsl:variable name='_it'> 
     <em>a</em> 
     <em>b</em> 
     <em>c</em> 
     <em>d</em> 
    </xsl:variable> 
    <!-- create a node-set from the result tree fragment --> 
    <xsl:variable name='it' select='exsl:node-set($_it)'/> 
    <Root> 
     <a> 
      <!-- 
       this is a normal xpath with the variable '$it' and a node 'em' 
       the number in brackets is the index starting with 1 
      --> 
      <xsl:value-of select='$it/em[1]'/> <!-- a --> 
      <xsl:value-of select='$it/em[2]'/> <!-- b --> 
     </a> 
    </Root> 
</xsl:template> 

<!-- MS doesn't provide exslt --> 
<msxsl:script language='JScript' implements-prefix='exsl'> 
    this['node-set'] = function (x) { 
     return x; 
    } 
</msxsl:script> 

</xsl:stylesheet> 
관련 문제