Copied to clipboard

Flag this post as spam?

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


  • Amir 75 posts 224 karma points
    Mar 16, 2014 @ 20:46
    Amir
    0

    To use a result tree fragment in a path expression, first convert it to a node-set using the msxsl:node-set() function

    I have following XSLT code:

    <xsl:stylesheet
      version="1.0"
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
      xmlns:exslt="http://exslt.org/common"
      xmlns:msxml="urn:schemas-microsoft-com:xslt" xmlns:umbraco.library="urn:umbraco.library" xmlns:Exslt.ExsltCommon="urn:Exslt.ExsltCommon"
      xmlns:Exslt.ExsltDatesAndTimes="urn:Exslt.ExsltDatesAndTimes"  xmlns:Exslt.ExsltMath="urn:Exslt.ExsltMath"
      xmlns:Exslt.ExsltRegularExpressions="urn:Exslt.ExsltRegularExpressions" xmlns:Exslt.ExsltStrings="urn:Exslt.ExsltStrings"
      xmlns:DesignetExtender ="urn:DesignetExtender"
      xmlns:Exslt.ExsltSets="urn:Exslt.ExsltSets"
      exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath 
      Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets DesignetExtender ">

    .......

    <xsl:variable name="test">
    <xsl:value-of select="exslt:node-set($HtmlPermulations)" disable-output-escaping="yes"/>
    </xsl:variable>

    Value for HtmlPermulations is as follow:

    &lt;root&gt;&lt;item&gt;Stationcar
                                            &lt;/item&gt;&lt;item&gt;Cabriolet
                                            &lt;/item&gt;&lt;item&gt;SUV&lt;/item&gt;&lt;item&gt;Stationcar
                                             Cabriolet&lt;/item&gt;&lt;item&gt;Stationcar
                                             SUV&lt;/item&gt;&lt;item&gt;Cabriolet
                                             SUV&lt;/item&gt;&lt;item&gt;Stationcar
                                             Cabriolet
                                             SUV&lt;/item&gt;&lt;/root&gt;

    But when I am trying to use it in this for-each loop:

    <xsl:for-each select="$test/root/item">
     <xsl:value-of select="."/>
    </xsl:for-each>

    I am getting this error message:

    To use a result tree fragment in a path expression, first convert it to a node-set using the msxsl:node-set() function.

    Can anyone help?

     

     

     

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Mar 16, 2014 @ 20:56
    Jan Skovgaard
    1

    Hi Amir

    If you ditch the test-variable and write this instead, what happens then?

    <xsl:for-each select="msxsl:node-set($HtmlPermulations/root/item)">
    <xsl:value-of select="." />
    </xsl:for-each>

    /Jan

  • Amir 75 posts 224 karma points
    Mar 16, 2014 @ 21:05
    Amir
    0

    I do not have msxsl, so Do you mean:

    <xsl:for-each select="msxml:node-set($HtmlPermulations/root/item)">
                                <xsl:value-of select="." />
     </xsl:for-each>                   

    ?

    if so, I am getting this error:

    Expression must evaluate to a node-set.

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Mar 16, 2014 @ 21:09
    Jan Skovgaard
    1

    Hi Amir

    Argh, I made a mistake in my example above. the /root/item part should be after the closing paranthesis. So write it like this instead

    <xsl:for-each select="msxml:node-set($HtmlPermulations)/root/item">
           <xsl:value-of select="." />
    </xsl:for-each>

    Does it work now?

    /Jan

  • Amir 75 posts 224 karma points
    Mar 16, 2014 @ 21:21
    Amir
    0

    It does not go through the loop.

    I think its because of the HTML format as its having


    &lt;

    and

    &gt;

    Am I right?

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Mar 16, 2014 @ 22:09
    Jan Skovgaard
    1

    Hi Amir

    Well to me it looks like XML that is returned but yes that is probably the reason. Why is it returned like that? (Missed it in the other post).

    /Jan

  • Amir 75 posts 224 karma points
    Mar 16, 2014 @ 22:17
    Amir
    0

    This string is being generated in a class extention as below:

    <xsl:variable name="HtmlPermulations" select="DesignetExtender:HTMLCombinations($csvCarTypes)"/>

    How can I disable-output-escaping for this?

    I tried it using test:

    <xsl:variable name="test">
    <xsl:value-of select="$HtmlPermulations" disable-output-escaping="yes"/>
    </xsl:variable>

    but still test is holding invalid characters.

     

    Any suggestions?

     

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Mar 16, 2014 @ 22:23
    Jan Skovgaard
    1

    Hi Amir

    Who have written the "DesignetExter" extension? It's probably in the underlying C# code there that something needs to be changed in order to have the proper XML output.

    /Jan

  • Amir 75 posts 224 karma points
    Mar 16, 2014 @ 22:27
    Amir
    0

    Hi Jan,

    I have developed it my self and here is the code:

     

    public static string HTMLCombinations(string csvString)
            {
                string retVal = String.Empty;
                List<string> list = GeneratePermulation(csvString);

                retVal += "<root>";
                foreach (string item in list)
                {
                    retVal += "<item>" + item + "</item>";
                }

                retVal += "</root>";

                return retVal;
            }

    Any clue?

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Mar 16, 2014 @ 22:45
    Jan Skovgaard
    1

    Hi Amir

    Ok, at a first glance that looks fine to me. But I'm not a backed developer so I might be missing something.

    However I just glanced through the posts again and saw that you also have a $csvVartypes variable. Could you please post the whole source code of the XSLT file so we get the full context?

    Thanks,
    Jan 

  • Amir 75 posts 224 karma points
    Mar 16, 2014 @ 23:02
    Amir
    0

    Hi Jan,

    csvCarTypes is as below:

    <xsl:variable name="csvCarTypes">
                                <xsl:for-each select="$currentPage/homePageCaseStudyCars/MultiNodePicker/nodeId">
                                    <xsl:variable name="thisCarItem" select="umbraco.library:GetXmlNodeById(./text())"/>
                                    <xsl:choose>
                                        <xsl:when test="position() = 1">
                                            <xsl:value-of select="umbraco.library:GetXmlNodeById($thisCarItem/carType)/typeName"/>
                                        </xsl:when>
                                        <xsl:otherwise>
                                            ,<xsl:value-of select="umbraco.library:GetXmlNodeById($thisCarItem/carType)/typeName"/>
                                        </xsl:otherwise>
                                    </xsl:choose>
                                </xsl:for-each>
    </xsl:variable>

    It generates string like 'Stationcar,Cabriolet,SUV' and this value is being sent to the extension and the resulted string is like what I have posted earlier.

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Mar 16, 2014 @ 23:08
    Jan Skovgaard
    1

    Hi Amir

    Ok, thanks.

    XSLT is probably not the ideal language to be using for stuff like this...however it should work from what I can tell so I'm a bit puzzled as to why you get those strings.

    Is the XSLT file saved using UTF-8 encoding? You should not need to escape the output when it's used like you're doing above. It's usually when you want to render content from for instance a rich text editor property that you need it.

    /Jan

  • Amir 75 posts 224 karma points
    Mar 16, 2014 @ 23:21
    Amir
    0

    I am Backend developer. I needed to generate a full combinatoin of given list of car types and doing this in XSLT is a big mess. So I created this extension. the input text is : "Stationcar,Cabriolet,SUV" and the output text is "Stationcar, Cabriolet, SUV, Stationcar Cabriolet, Stationcar SUV, Cabriolet SUV, Stationcar Cabriolet SUV"

    In order to manage it in XSLT the only way comes to my mind was convert it to an XML format.

    Do you have any better idea?

  • Amir 75 posts 224 karma points
    Mar 16, 2014 @ 23:31
    Amir
    0

    Jan,

    Do you know how can I split a comma separated value (Stationcar,Cabriolet,SUV" and the output text is "Stationcar, Cabriolet, SUV, Stationcar Cabriolet, Stationcar SUV, Cabriolet SUV, Stationcar Cabriolet SUV) to be used in a xslt for-each loop?

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Mar 16, 2014 @ 23:45
    Jan Skovgaard
    1

    Hi Amir

    Of course making an XSLT extension is a good thing. No doubt about that but some of the values you need and the way you need to loop through them are a bit messy. Not saying it can be done and the approach with your extension is indeed good :)

    Umbraco delivers some XSLT extensions and one of them is Split, that is used for splitting up comma-seperated content. It can be used like <xsl:variable name="cars" select="umbraco.library:Split(nameofyourumbracoproperty,',')" /> - The first parameter is your property alias and the second parameter is the character you want to split it by. In your case "comma".

    By writing

    <textarea>
    <xsl:copy-of select="$cars" />
    </textarea>

    You should see some XML output like this

    <values>
    <value>Value 1</value>
    <value>Value 2</value>
    </values>

    Is this what you're after?

    Cheers,
    Jan 

  • Amir 75 posts 224 karma points
    Mar 17, 2014 @ 00:27
    Amir
    0

    Thans Jan,

    Its kindo solved my problem.

    But still its I am getting some strange HTML variables

    My Xslt is now like :

     
    <xsl:variablename="AllPossiblePermulations"select="DesignetExtender:GenerateCombinations($csvCarTypes)"/>

                           
    <xsl:variablename="types"select="umbraco.library:Split($AllPossiblePermulations,',')"  xml:space="default"/>

                           
    <xsl:variablename="normalizedTypes">
                               
    <xsl:copy-ofselect="$types"/>
                           
    </xsl:variable>
    from Here
                           
    <xsl:for-eachselect="msxml:node-set($normalizedTypes)/values/*">
                               
    <div>
                                   
    <xsl:attributename="class">
                                       
    <xsl:value-ofselect="."/>
                                   
    </xsl:attribute>
                               
    </div>
                           
    </xsl:for-each>
    ToHere

     

    and the output html is:

     

    From Here <div class="Stationcar&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&#x9;&#x9;&#x9;&#x9;&#x9;" /><div class="Cabriolet&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&#x9;&#x9;&#x9;&#x9;&#x9;" /><div class="SUV" /><div class="Stationcar&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&#x9;&#x9;&#x9;&#x9;&#x9; Cabriolet" /><div class="Stationcar&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&#x9;&#x9;&#x9;&#x9;&#x9; SUV" /><div class="Cabriolet&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&#x9;&#x9;&#x9;&#x9;&#x9; SUV" /><div class="Stationcar&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&#x9;&#x9;&#x9;&#x9;&#x9; Cabriolet&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&#x9;&#x9;&#x9;&#x9;&#x9; SUV" /> To Here

     

     

    I am not sure where exactlt these html codes are coming from

    While If I dont use the loop for populating classes and put the value directly inside the a div, the output Html would be like this:

    FromHere
                           
    <xsl:for-each select="msxml:node-set($normalizedTypes)/values/*">
                               
    <div>
                                   
                                       
    <xsl:value-of select="."/>
                                   
                               
    </div>
                            </
    xsl:for-each>
    ToHere
    FromHere  <div>Stationcar  </div><div>Cabriolet  </div><div>SUV</div><div>Stationcar  Cabriolet</div><div>Stationcar  SUV</div><div>Cabriolet  SUV</div><div>Stationcar  Cabriolet  SUV</div>ToHere

     

    Have any idea whats going on here?

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Mar 17, 2014 @ 09:34
    Jan Skovgaard
    1

    Could you please show me the output of the $types varaible?

    Just write it out in a textarea exactly like below - no use of xml:space or any other attributes.

    <textarea>
    <xsl:copy-of select="$types" />
    </textarea> 

    /Jan

  • Amir 75 posts 224 karma points
    Mar 17, 2014 @ 19:36
    Amir
    0

    Hi Jan,

    Thanks and sorry for the late reply.

    The requested output is as below:

    <textarea><values><value>Stationcar </value><value>Cabriolet </value><value>SUV</value><value>Stationcar Cabriolet</value><value>Stationcar SUV</value><value>Cabriolet SUV</value><value>Stationcar Cabriolet SUV</value></values></textarea>


    It looks fine, but when I try following code:

    <xsl:for-each select="msxml:node-set($normalizedTypes)/values/*">
                                <div>
                                    <xsl:attribute name="class">
                                       
                                        <xsl:value-of select="."/>
                                    </xsl:attribute>
                                </div>
    </xsl:for-each>

    the output is as follow which is a bit messy!

    <div class="Stationcar&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&#x9;&#x9;&#x9;&#x9;&#x9;" /><div class="Cabriolet&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&#x9;&#x9;&#x9;&#x9;&#x9;" /><div class="SUV" /><div class="Stationcar&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&#x9;&#x9;&#x9;&#x9;&#x9; Cabriolet" /><div class="Stationcar&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&#x9;&#x9;&#x9;&#x9;&#x9; SUV" /><div class="Cabriolet&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&#x9;&#x9;&#x9;&#x9;&#x9; SUV" /><div class="Stationcar&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&#x9;&#x9;&#x9;&#x9;&#x9; Cabriolet&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&#x9;&#x9;&#x9;&#x9;&#x9; SUV" />

     


  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Mar 17, 2014 @ 20:45
    Jan Skovgaard
    100

    Hi Amir

    Ok, are you somewhere in your code using either xsl:strip-space or xsl:preserve-space?

    Otherwise try writing you value-of like this <xsl:value-of select="normalize-space(.)" />

    Hope this helps.

    /Jan

  • Amir 75 posts 224 karma points
    Mar 17, 2014 @ 21:24
    Amir
    0

    Yessssssss,

    normalize-space(.) works. Awsome Jan. Thanks alot.

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Mar 17, 2014 @ 21:28
    Jan Skovgaard
    0

    Hi Amir

    Glad to hear it finally worked out :)

    /Jan

Please Sign in or register to post replies

Write your reply to:

Draft