2017-01-26 47 views
0

我如何能够在XSLT中设置变量的值?如何使用嵌套属性来设置XSLT中的值

我现在有一个xml像这样:

<field name="Average Bitrate" timecode="01:35:14:300" value="60.01" /> 
<field name="Display Aspect Ratio" value="16:9" /> 
<field name="GOP Structure"> 

我想创建一个名为纵横比可变的。此变量需要具有属性Display Aspect Ratio的节点字段下的条件。在这种情况下,值将被16:9

这里是我的XSLT的例子:

<xsl:variable name="root" select="$cfg//taskReport/streamnode/info/"/> 
<xsl:variable name="AspectRatio" select="$root/Field[name = 'Display Aspect Ratio']"> 
    <xsl:value-of select="$AspectRatio/@value"/> 
</xsl:variable> 

我需要做什么才能让我期望的结果来改变?

+0

由于缺乏上下文,回答您的问题几乎是不可能的。我们不知道有关'field'的真正路径,我们不知道您在XSLT样式表中的位置。你向我们展示了未定义的变量,例如'$ cfg'。 –

回答

0

鉴于以下输入:

XML

<root> 
    <field name="Average Bitrate" timecode="01:35:14:300" value="60.01" /> 
    <field name="Display Aspect Ratio" value="16:9" /> 
    <field name="GOP Structure"/> 
</root> 

以下样式:

XSLT 1.0

<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/> 

<xsl:template match="/"> 
    <xsl:variable name="AspectRatio" select="/root/field[@name='Display Aspect Ratio']/@value" /> 
    <test> 
     <xsl:value-of select="$AspectRatio"/> 
    </test> 
</xsl:template> 

</xsl:stylesheet> 

将返回:

<?xml version="1.0" encoding="UTF-8"?> 
<test>16:9</test> 

注意,XML是大小写敏感的; Field不选择field

相关问题