$referenceName
은 "unumericValue"라는 이름을 가진 변수에 대한 참조가 아니거나 그렇지 않습니다. 문자열 값은 "unumericValue"입니다. 따라서 절대 값은 $min
보다 클 수 없습니다. 그러나, 약간의 추가 작업으로, 이름으로 변수를 찾을 수있는 트릭이있다 : 여기서주의 할
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:variable name="numericValue" select="10" />
<xsl:variable name="anotherValue" select="8" />
<xsl:variable name="vars" select="document('')/*/xsl:variable" />
<xsl:template match="/">
<xsl:variable name="referenceName" select="'numericValue'" />
<xsl:variable name="referenceValue" select="$vars[@name = $referenceName]/@select" />
Reference value: <xsl:value-of select="$referenceValue" />
</xsl:template>
</xsl:stylesheet>
하나의 큰 제한이 단지 일정한 숫자 값입니다 변수 일 것입니다. 마지막으로, 계산 된 값과 변수를 시뮬레이션 할 수있는 방법이
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:v="variables-node"
>
<v:variables>
<v:variable n="numericValue" value="10" />
<v:variable n="nonNumericValue" value="Hello World" />
</v:variables>
<xsl:variable name="vars" select="document('')//v:variables/v:variable" />
<xsl:template match="/">
<xsl:variable name="referenceName" select="'nonNumericValue'" />
<xsl:variable name="referenceValue" select="$vars[@n = $referenceName]/@value" />
<xsl:value-of select="concat('The variable with the name ', $referenceName, ' has the value ', $referenceValue)"/>
</xsl:template>
</xsl:stylesheet>
그리고 :
이
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:exslt="http://exslt.org/common"
>
<xsl:variable name="varsRaw">
<var n="computedValue" value="{concat('2 + 4 is ', 2 + 4)}" />
<var n="computedNumber" value="{22 div 7}" />
</xsl:variable>
<xsl:variable name="vars" select="exslt:node-set($varsRaw)/var" />
<xsl:template match="/">
<xsl:variable name="referenceName" select="'computedValue'" />
<xsl:variable name="referenceValue" select="$vars[@n = $referenceName]/@value" />
<xsl:value-of select="concat('The variable with the name ', $referenceName, ' has the value ', $referenceValue)"/>
<xsl:value-of select="' '"/>
<xsl:variable name="referenceName2" select="'computedNumber'" />
<xsl:variable name="referenceValue2" select="$vars[@n = $referenceName2]/@value" />
<xsl:value-of select="concat('The variable with the name ', $referenceName2, ' has the value ', $referenceValue2)"/>
</xsl:template>
</xsl:stylesheet>
마지막 방법은 실제로 아마도 가장 정통입니다 여기에
는 상수 문자열 값으로 변수를 시뮬레이션하는 방법 그러나 XSLT 프로세서 종속성 (적어도 XSLT 1.0에서는)
node-set()
기능이 필요합니다.
고마워요. 첫 번째 제안은 저에게 큰 도움이되었습니다. – eadrax