0

I'm trying to retrieve a certain value from an XML document and output that value into a new XML document - the source XML is full of unused data, I only need the specific part.

Source XML :-

<dpp:Programme xmlns:dpp="http://www.digitalproductionpartnership.co.uk/ns/as11/2012" xmlns:itv="http://dpp.itv.com/timecodes/v1">
<dpp:Editorial>
<dpp:SeriesTitle>test</dpp:SeriesTitle>
<dpp:ProgrammeTitle>test</dpp:ProgrammeTitle>
<dpp:EpisodeTitleNumber>test</dpp:EpisodeTitleNumber>
<dpp:ProductionNumber>2/1993/0022#001</dpp:ProductionNumber>
<dpp:Synopsis>None</dpp:Synopsis>
<dpp:Originator>None</dpp:Originator>
<dpp:CopyrightYear>2013</dpp:CopyrightYear>
</dpp:Editorial>
<dpp:Technical>
<dpp:ShimName>UK DPP HD</dpp:ShimName>
<dpp:Video>
<dpp:VideoBitRate unit="Mbps">100</dpp:VideoBitRate>
<dpp:VideoCodec>AVCI</dpp:VideoCodec>
<dpp:VideoCodecParameters>High 4:2:2 level 4.1</dpp:VideoCodecParameters>
<dpp:PictureFormat>1080i50 16:9</dpp:PictureFormat>
<dpp:AFD>10</dpp:AFD>
<dpp:PictureRatio>16:9</dpp:PictureRatio>
<dpp:ThreeD>false</dpp:ThreeD>
<dpp:ProductPlacement>false</dpp:ProductPlacement>
<dpp:FPAPass>Not tested</dpp:FPAPass>
</dpp:Video>
<dpp:Audio>
<dpp:AudioSamplingFrequency unit="kHz">48</dpp:AudioSamplingFrequency>
<dpp:AudioBitDepth>24</dpp:AudioBitDepth>
<dpp:AudioCodecParameters>PCM</dpp:AudioCodecParameters>
<dpp:AudioTrackLayout>EBU R 123: 4b</dpp:AudioTrackLayout>
<dpp:PrimaryAudioLanguage>eng</dpp:PrimaryAudioLanguage>
<dpp:SecondaryAudioLanguage>zxx</dpp:SecondaryAudioLanguage>
<dpp:TertiaryAudioLanguage>eng</dpp:TertiaryAudioLanguage>
<dpp:AudioLoudnessStandard>EBU R 128</dpp:AudioLoudnessStandard>
</dpp:Audio>
<dpp:Timecodes>
<dpp:LineUpStart>09:58:00:00</dpp:LineUpStart>
<dpp:IdentClockStart>09:59:20:00</dpp:IdentClockStart>
<dpp:Parts>
<dpp:Part>
<dpp:PartNumber>1</dpp:PartNumber>
<dpp:PartTotal>1</dpp:PartTotal>
<dpp:PartSOM>10:30:41:11</dpp:PartSOM>
<dpp:PartDuration>00:00:30:13</dpp:PartDuration>
</dpp:Part>
</dpp:Parts>
<dpp:TotalNumberOfParts>1</dpp:TotalNumberOfParts>
<dpp:TotalProgrammeDuration>00:00:30:13</dpp:TotalProgrammeDuration>
</dpp:Timecodes>
<dpp:AccessServices>
<dpp:AudioDescriptionPresent>false</dpp:AudioDescriptionPresent>
<dpp:ClosedCaptionsPresent>false</dpp:ClosedCaptionsPresent>
<dpp:OpenCaptionsPresent>false</dpp:OpenCaptionsPresent>
<dpp:SigningPresent>No</dpp:SigningPresent>
</dpp:AccessServices>
<dpp:Additional>
<dpp:CompletionDate>2014-01-07</dpp:CompletionDate>
<dpp:TextlessElementExist>false</dpp:TextlessElementExist>
<dpp:ProgrammeHasText>true</dpp:ProgrammeHasText>
<dpp:ProgrammeTextLanguage>eng</dpp:ProgrammeTextLanguage>
<dpp:AssociatedMediaFilename>2-1993-0022-001.mxf</dpp:AssociatedMediaFilename>
<dpp:MediaChecksumType>MD5</dpp:MediaChecksumType>
<dpp:MediaChecksumValue>6154fd9cf312492e2dea68bee656ded7</dpp:MediaChecksumValue>
</dpp:Additional>
<dpp:ContactInformation>
<dpp:ContactEmail>None</dpp:ContactEmail>
<dpp:ContactTelephoneNumber>None</dpp:ContactTelephoneNumber>
</dpp:ContactInformation>
</dpp:Technical>
<itv:AdditionalTimeCodes>
<itv:Element>
<itv:ElementType>Essence</itv:ElementType>
<itv:ElementSOM>10:30:41:11</itv:ElementSOM>
<itv:Duration>00:00:30:13</itv:Duration>
<itv:Fade>false</itv:Fade>
<itv:Mix>false</itv:Mix>
<itv:Property>Essence</itv:Property>
</itv:Element>
</itv:AdditionalTimeCodes>
</dpp:Programme>

This is the XSL I have created :-

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


            <xsl:for-each select="Programme/Technical/Timecodes">
                <tr>
                    <td>
                        <xsl:value-of select="TotalProgrammeDuration"/>

                    </td>
                </tr>
            </xsl:for-each>

        </body>
    </html>
</xsl:template>
</xsl:stylesheet>

But all I'm getting returned is a blank page?

All I need is the timecode value (TotalProgrammeDuration) from Programme/Technical/Timecodes

What am I doing wrong? (I'm very new to this - if you can't rell already)

J.

2 Answers 2

2

The elements in your input XML have a namespace. You need to declare this namespace in your XSLT stylesheet too - and prefix any element names you mention.

Namespaces are an important concept in XSLT (as with XML technologies in general) so I recommend you spend some time understanding the basics. For instance, start with a previous answer of mine.

Stylesheet

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:dpp="http://www.digitalproductionpartnership.co.uk/ns/as11/2012">
<xsl:output method="text" indent="yes"/>
<xsl:template match="/">
    <html>
        <body>
            <xsl:for-each select="dpp:Programme/dpp:Technical/dpp:Timecodes">
                <tr>
                    <td>
                        <xsl:value-of select="dpp:TotalProgrammeDuration"/>
                    </td>
                </tr>
            </xsl:for-each>
        </body>
    </html>
</xsl:template>
</xsl:stylesheet>

Also note that you are obviously outputting XHTML. Then, it makes more sense to set

<xsl:output method="text">

to

<xsl:output method="html">

Further, indent="yes" only makes sense when used with html, not with text.

Below is a second attempt at writing your stylesheet that uses separate templates (which is generally a better idea than using xsl:for-each).

Stylesheet (a better approach)

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
   xmlns:dpp="http://www.digitalproductionpartnership.co.uk/ns/as11/2012">

   <xsl:output method="html" indent="yes"/>

   <xsl:template match="/">
      <html>
         <body>
            <xsl:apply-templates/>
         </body>
      </html>
   </xsl:template>

   <xsl:template match="dpp:Timecodes">
      <tr>
         <td>
            <xsl:value-of select="dpp:TotalProgrammeDuration"/>
         </td>
      </tr>
   </xsl:template>

   <xsl:template match="text()"/>

</xsl:stylesheet>

Output

<html xmlns:dpp="http://www.digitalproductionpartnership.co.uk/ns/as11/2012">
   <body>
      <tr>
         <td>00:00:30:13</td>
      </tr>
   </body>
</html>
Sign up to request clarification or add additional context in comments.

1 Comment

+1 for a good push approach, but I'd also add exclude-result-prefixes="dpp" to xsl:stylesheet.
1

You are missing namespace declarations:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:dpp="http://www.digitalproductionpartnership.co.uk/ns/as11/2012" exclude-result-prefixes="dpp">
<xsl:output method="html" indent="yes"/>
<xsl:template match="/">
    <html>
        <body>
            <xsl:for-each select="dpp:Programme/dpp:Technical/dpp:Timecodes">
                <tr>
                    <td>
                        <xsl:value-of select="dpp:TotalProgrammeDuration"/>
                    </td>
                </tr>
            </xsl:for-each>
        </body>
    </html>
</xsl:template>
</xsl:stylesheet>

2 Comments

Thanks - Could you also advice how to output as a timecode rather than just text?
I didn't get you. Do you mean you want to add the whole TimeCodes node?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.