XSLT Format refrerencing dynamic Metadata

James's Avatar

James

18 Jan, 2011 03:59 PM

Hello,

I have an Index Block that produces the following XML:

<system-index-block name="my_video_library" type="folder" current-time="1295365448415">
<system-folder id="80689808867e488e01664cde40548f83">
    <name>Bridgeforth Stadium</name>
    <created-by>johns2ja</created-by>
    <created-on>1294939494390</created-on>
    <last-modified-by>johns2ja</last-modified-by>
    <last-modified>1295033394726</last-modified>

    <dynamic-metadata>
        <name>youtubeVideoID</name>
        <value>GxibToE1S7A</value>
    </dynamic-metadata>

    <dynamic-metadata>
        <name>embedded</name>
        <value>Yes</value>
    </dynamic-metadata>
</system-folder>

<system-folder id="8067d399867e488e01664cdec3421db2">
    <name>Be The Change</name>
    <created-by>johns2ja</created-by>
    <created-on>1294939444093</created-on>
    <last-modified-by>johns2ja</last-modified-by>
    <last-modified>1295033386435</last-modified>

    <dynamic-metadata>
        <name>youtubeVideoID</name>
        <value>A_A3fRxgeCg</value>
    </dynamic-metadata>

    <dynamic-metadata>
        <name>embedded</name>
        <value>No</value>
    </dynamic-metadata>
</system-folder>
</system-index-block>

I am applying the following XSLT Format to it to produce output:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="system-index-block">
    <xsl:for-each select="system-folder">
        <xsl:apply-templates select="system-folder[dynamic-metadata[name = 'embedded']/value = 'Yes']">
        </xsl:apply-templates>
    </xsl:for-each>
</xsl:template>
<xsl:template match="system-index-block">

    <h2><xsl:value-of select="system-folder/name"/></h2>
    <object data="http://www.youtube.com/v/{system-folder/dynamic-metadata[name='youtubeVideoID']/value}?fs=1&amp;hl=en_US" height="385" type="application/x-shockwave-flash" width="640">
        <param name="movie" value=" http://www.youtube.com/v/{system-folder/dynamic-metadata[name='youtubeVideoID']/value}?fs=1&amp;hl=en_US"/>
        <param name="allowFullScreen" value="true"/>
    </object>
    <p>Is this set to be embedded? <xsl:value-of select="system-folder/dynamic-metadata[name = 'embedded']/value"/></p>
    <br/>

</xsl:template>
</xsl:stylesheet>

However, what I am running into is that the only rendering is of the video that appears first in the order. The dynamic metadata is ignored. While I can get the dynamic metadata value to show up as what was selected, I cannot get it to render or not render based on the choice. I have attempted to use <xsl:if ...> to no avail. What am I missing?

  1. 1 Posted by James on 19 Jan, 2011 04:25 PM

    James's Avatar

    Apparently apply-templates and xsl:if's don't seem to work nicely together, at least in Cascade. This code worked for the XSL format:

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:template match="system-index-block/system-folder">
        <xsl:if test="dynamic-metadata[name = 'embedded']/value = 'Yes'">
            <h2>
                <xsl:value-of select="name"/>
            </h2>
            <object data="http://www.youtube.com/v/{dynamic-metadata[name='youtubeVideoID']/value}?fs=1&amp;hl=en_US" height="385" type="application/x-shockwave-flash" width="640">
                <param name="movie" value=" http://www.youtube.com/v/{system-folder/dynamic-metadata[name='youtubeVideoID']/value}?fs=1&amp;hl=en_US"/>
                <param name="allowFullScreen" value="true"/>
            </object>
            <p>Is this set to be embedded? <xsl:value-of select="dynamic-metadata[name = 'embedded']/value"/>
            </p>
            <br/>
        </xsl:if>
    </xsl:template>
    </xsl:stylesheet>
    
  2. 2 Posted by Ross on 07 Mar, 2011 03:54 PM

    Ross's Avatar

    James,

    Your second example is well-constructed XSLT. I'm not sure what you mean about apply-templates and if not working together. The problem with your first example, was that you nested apply-templates inside of for-each, essentially looking for "folders within folders":

    <xsl:for-each select="system-folder">
        <xsl:apply-templates select="system-folder[dynamic-metadata[name = 'embedded']/value = 'Yes']">
        </xsl:apply-templates>
    </xsl:for-each>
    

    … would look for something at /system-index-block/system-folder/system-folder. You could make that statement correct by simply removing the xsl:for-each element.

    Ross

  3. Ross closed this discussion on 07 Mar, 2011 03:54 PM.

  4. Jamie johnson re-opened this discussion on 08 Mar, 2011 04:01 PM

  5. 3 Posted by Jamie johnson on 08 Mar, 2011 04:01 PM

    Jamie johnson's Avatar
  6. Tim closed this discussion on 08 Mar, 2011 04:37 PM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac