Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Paul 55 posts 76 karma points
    Nov 14, 2011 @ 02:02
    Paul
    0

    Need help parsing an array in a for-each loop

    I have the following

    <xsl:variable name="Categories">
      <Category Item="A" />
      <Category Item="B" />
      <Category Item="C" />
      <Category Item="D" />
      <Category Item="D" />
    </xsl:variable>

     

    I will like to use it in the following by concatenating the curent category in the for-each loop to an attribute in order to

    get the value of that attribute

              <xsl:for-each select="Categories">
                
                <tr class="odd">
                  <td align="left" style="height:48px;">
                    <xsl:value-of select="umbraco.library:ReplaceLineBreaks($currentPage/* [@alias = concat('Dept', @Item)])" disable-output-escaping="yes"/>
                   </td>

    ....

    </tr>

    </xsl:for-each>

    ...


    The issue I am seeing is it is not even transversing the loop

     

    Please help

  • Chriztian Steinmeier 2798 posts 8788 karma points MVP 7x admin c-trib
    Nov 14, 2011 @ 09:07
    Chriztian Steinmeier
    0

    Hi Paul,

    It's hard to know until you've tried it, but you need to convert an XML variable into a node-set to be able to query it with XPath - it's easy to do. Here's a full sample.

    <?xml version="1.0" encoding="utf-8" ?>
    <xsl:stylesheet
        version="1.0"
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
        xmlns:umb="urn:umbraco.library"
        xmlns:make="urn:schemas-microsoft-com:xslt"
        exclude-result-prefixes="umb make"
    >
    
        <xsl:output method="xml" indent="yes" omit-xml-declaration="yes" />
    
        <xsl:param name="currentPage" />
    
        <xsl:variable name="CategoriesProxy">
            <Category Item="A" />
            <Category Item="B" />
            <Category Item="C" />
            <Category Item="D" />
            <Category Item="E" />
        </xsl:variable>
        <xsl:variable name="categories" select="make:node-set($categoriesProxy)" />
    
        <xsl:template match="/">
            <xsl:for-each select="$categories/Category">
                <tr class="odd">
                    <td align="left" style="height:48px;">
                        <xsl:value-of select="umbraco.library:ReplaceLineBreaks($currentPage/*[name() = concat('Dept', current()/@Item)])" disable-output-escaping="yes" />
                    </td>
                    ...
                </tr>
            </xsl:for-each>       
        </xsl:template>
    
    </xsl:stylesheet>
    
    

    Note that I've changed the reference to @alias - if you're actually using the old XML schema you can change it back.

    /Chriztian 

     

  • Paul 55 posts 76 karma points
    Nov 15, 2011 @ 02:12
    Paul
    0

    I receive the following exception even after add "umb make" to the exclude-result-prefixes section.Just as shown.

    exclude-result-prefixes="msxml umb make umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets tagsLib BlogLibrary umb make">

    The error I receive is:

    System.Xml.Xsl.XslLoadException: Prefix 'make' is not defined. An error occurred at C:\inetpub\wwwroot\localhost\xslt\634568945636893025_temp.xslt(16,3). 
    at System.Xml.Xsl.XslCompiledTransform.LoadInternal(Object stylesheet, XsltSettings settings, XmlResolver stylesheetResolver) 
    at umbraco.presentation.webservices.codeEditorSave.SaveXslt(String fileName, String oldName, String fileContents, Boolean ignoreDebugging)

  • Paul 55 posts 76 karma points
    Nov 15, 2011 @ 02:21
    Paul
    0

    By replacing make with msxml and replacing a call to the function ReplaceLineBreaks by GetMdia for an image file. It worked! 

    Thanks a billion!

  • Chriztian Steinmeier 2798 posts 8788 karma points MVP 7x admin c-trib
    Nov 15, 2011 @ 09:38
    Chriztian Steinmeier
    0

    Hi Paul,

    Just to clarify:

    - The reason for the "Prefix 'make' is not defined" error would be because you forgot to add the xmlns:make="...." just above the exclude-result-prefixes="..." line.

    - The default Umbraco templates adds this namespace with the prefix msxml instead - I just like make better because the function call makes more sense to me :-) The crucial part of using namespaces is the actual namespace-URI (urn:schemas-microsoft-com:xslt).

    /Chriztian

Please Sign in or register to post replies

Write your reply to:

Draft