XSL需要帮助获得价值

时间:2014-04-14 15:34:29

标签: xml xslt

我是XSLT的新手,我正在尝试获取以下信息。

我有一个如下所示的XML:

<?xml version="1.0" encoding="utf-8"?>
<soa:Label identifier="624e35e5-f7fe-49d2-b7d6-669543106161" name="Metadata Label" description="This label holds two fields, the duration and the file name of a media file.  It is intended to be populated using Identify." instance="1ab96760-b2f2-439d-8c26-ef204236b3ec" signature="00000000-0000-0000-0000-000000000000" xmlns:soa="urn:telestream.net:soa:core">
  <soa:Category identifier="007cf696-0ee3-4bbf-8d1a-5fc90b75ae82" name="Video" order="0" />
  <soa:Category identifier="f6754a00-a901-4cfe-b500-737506a67da5" name="Audio" order="0" />
  <soa:Parameter type="timecode" identifier="f74643ba-085e-4a89-8362-a222720a4c4e" bindable="True" name="Duration" enabled="true" disableable="false">
    00:00:00:00@25<soa:Default>z00:00:00:00@25</soa:Default>
    <soa:IsRequired>false</soa:IsRequired>
  </soa:Parameter>
  <soa:Parameter type="string" identifier="72584048-c72f-46c3-9dd7-f4da519bfb70" bindable="True" name="File Name" enabled="true" disableable="false">
    Default.mpg<soa:Default>Default.mpg</soa:Default>
    <soa:Option>Default.mpg</soa:Option>
    <soa:IsRequired>false</soa:IsRequired>
  </soa:Parameter>
  <soa:Parameter type="int32" identifier="5cf311fc-2ef6-4886-a8db-1cb33b6bc6f0" bindable="True" name="Video Width" category="007cf696-0ee3-4bbf-8d1a-5fc90b75ae82" enabled="true" disableable="false">
    720<soa:Default>z720</soa:Default>
    <soa:IsRequired>false</soa:IsRequired>
  </soa:Parameter>
  <soa:Parameter type="int32" identifier="3fae6a7b-6a06-4d03-b2ab-65974ddcb6b1" bindable="True" name="Video Height" category="007cf696-0ee3-4bbf-8d1a-5fc90b75ae82" enabled="true" disableable="false">
    576<soa:Default>z576</soa:Default>
    <soa:IsRequired>false</soa:IsRequired>
  </soa:Parameter>
  <soa:Parameter type="int32" identifier="35ab87a9-535d-4ae2-b280-4cad204bb2a1" bindable="True" name="Audio Channels" category="f6754a00-a901-4cfe-b500-737506a67da5" enabled="true" disableable="false">
    2<soa:Default>2</soa:Default>
    <soa:IsRequired>false</soa:IsRequired>
  </soa:Parameter>
  <soa:Parameter type="string" identifier="19336ecc-9e6c-4f7e-ab40-18d95a5546f3" bindable="True" name="Video Codec" category="007cf696-0ee3-4bbf-8d1a-5fc90b75ae82" enabled="true" disableable="false">
    dvpal<soa:Default>dvpal</soa:Default>
    <soa:IsRequired>false</soa:IsRequired>
  </soa:Parameter>
  <soa:Parameter type="int32" identifier="16bb6aac-93b0-4074-b4bb-a0b0ded92940" bindable="True" name="Audio Bitrate" category="f6754a00-a901-4cfe-b500-737506a67da5" enabled="true" disableable="false">
    192<soa:Default>192</soa:Default>
    <soa:IsRequired>false</soa:IsRequired>
  </soa:Parameter>
  <soa:Parameter type="string" identifier="7e50585e-e30f-43d3-be49-9a488e2531f2" bindable="True" name="Audio Codec" category="f6754a00-a901-4cfe-b500-737506a67da5" enabled="true" disableable="false">
    pcm<soa:Default>pcm</soa:Default>
    <soa:IsRequired>false</soa:IsRequired>
  </soa:Parameter>
  <soa:Parameter type="int32" identifier="67aa5f6f-60fe-4d2a-a5f0-caca31ebe088" bindable="True" name="Audio Sample Rate" category="f6754a00-a901-4cfe-b500-737506a67da5" enabled="true" disableable="false">
    48<soa:Default>48</soa:Default>
    <soa:IsRequired>false</soa:IsRequired>
  </soa:Parameter>
</soa:Label>

我希望得到这个

   <Filename>Default.mpg</Filename>
   <Duration>00:00:00:00</Duration>
   <Video_Width>720</Video_Width>
   <Video_Height>576</Video_Height>

但我需要的价值是第一个

例如:

<soa:Parameter type="string" identifier="72584048-c72f-46c3-9dd7-f4da519bfb70" bindable="True" name="File Name" enabled="true" disableable="false">Default.mpg<soa:Default>...

Default.mpg代码需要Filename

目前我只能通过以下方式获得持续时间值:

<xsl:value-of select="substring-before(soa:Label/soa:Parameter,'@')"/>

1 个答案:

答案 0 :(得分:2)

我猜你需要这样的东西:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:soa="urn:telestream.net:soa:core" exclude-result-prefixes="soa">

<xsl:output method="xml" indent="yes"/>
<xsl:strip-space elements="*"/>

<xsl:template match="/">
    <root>
        <Filename>
            <xsl:value-of select="soa:Label/soa:Parameter[@name='File Name']/text()[1]"/>
        </Filename>
        <Duration>
            <xsl:value-of select="substring-before(soa:Label/soa:Parameter[@name='Duration']/text()[1],'@')"/>
        </Duration>
        <Video_Width>
            <xsl:value-of select="soa:Label/soa:Parameter[@name='Video Width']/text()[1]"/>
        </Video_Width>
        <Video_Height>
            <xsl:value-of select="soa:Label/soa:Parameter[@name='Video Height']/text()[1]"/>
        </Video_Height>
    </root>
</xsl:template>