简体   繁体   English

如何使用嵌套属性在XSLT中设置值

[英]How to use nested Attribute to set value in XSLT

How am I able to set the value of a variable in XSLT? 如何在XSLT中设置变量的值?

I currently have an xml like so: 我目前有这样的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">

I would like to create a variable called aspectratio. 我想创建一个称为Aspectratio的变量。 This variable needs to have the conditions under the node field with the attribute Display Aspect Ratio. 此变量需要在节点字段下具有属性“显示纵横比”的条件。 In this case the value would then be 16:9 在这种情况下,该值将为16:9

Here is an example of my XSLT: 这是我的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>

What do I need to change in order to get my desired result? 为了获得理想的结果,我需要更改什么?

Given the following input: 给出以下输入:

XML 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>

the following stylesheet: 以下样式表:

XSLT 1.0 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> 

will return: 将返回:

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

Note that XML is case-sensitive; 请注意,XML区分大小写; Field does not select field . Field不选择field

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM