Copied to clipboard

Flag this post as spam?

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


  • Michael Lykke 12 posts 75 karma points
    Feb 20, 2013 @ 00:55
    Michael Lykke
    0

    Save as file - xslt transformed - string-length problem

    Hi forum

    I'm trying to save form entries in a file using som xslt transformation. I'm pretty new to this so please bear with me if this is a totally noob question.

    I'm trying to count the string length of the value field but I must be doing something wrong. This is my xslt-file so far - which isn't working:

    <?xml version="1.0" encoding="utf-8"?>
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:user="urn:my-scripts" xmlns:umbraco.library="urn:umbraco.library" version="1.0" exclude-result-prefixes="xsl msxsl user umbraco.library">
        <xsl:output method="text" media-type="text/plain" indent="no" encoding="utf-8"/>
        <xsl:param name="records"/>
        <xsl:template match="/">
            <xsl:for-each select="$records//fields/child::*">
                <xsl:sort select="@pageindex" order="ascending"/>
                <xsl:sort select="@fieldsetindex" order="ascending"/>
                <xsl:sort select="@sortorder" order="ascending"/>
                <xsl:choose>
                    <xsl:when test="@fieldsetindex = 0">
    
                        <xsl:if test="@sortorder = 0">10</xsl:if>
    
                        <xsl:value-of select=".//value"/>
    
                    </xsl:when>
                    <xsl:otherwise>
    
    <xsl:if test="@sortorder = 0"><xsl:text>
    </xsl:text>20</xsl:if>
    <xsl:value-of select=".//value"/>
        <xsl:if test="string-length(.//value) &lt; 30">
            <xsl:text> - </xsl:text>
        </xsl:if>
    
                    </xsl:otherwise>
                </xsl:choose>
            </xsl:for-each>
            <xsl:text>
            </xsl:text>
        </xsl:template>
    </xsl:stylesheet>

    If I put some constant string in string-length like this

    <xsl:if test="string-length('some string') &lt; 30">

    it works as expected, but I can't figure out how to reference the value of the value tag. I think I may have to assign the value to a variable and use that, but I don't know how to do this.

    
    
    

    Can anyone please help me?

    Best regards,
    Michael

    Additional question: The default "Save as file"-workflow has an option to name file extension. I put "txt" in this field but it still saves the file as .xml. Can we do anything about this?

  • Comment author was deleted

    Feb 20, 2013 @ 09:18

    Hi Michael

    And does the <xsl:value-ofselect=".//value"/> tag output anything?

    Maybe you'll need to cast to string first

     

    <xsl:iftest="string-length(string(.//value)) &lt; 30">
  • Comment author was deleted

    Feb 20, 2013 @ 09:19

    For the save as file workflow I've added the issue to our tracker and a fix should be part of the next maintenance release 

    http://issues.umbraco.org/issue/CON-269

  • Michael Lykke 12 posts 75 karma points
    Feb 20, 2013 @ 10:04
    Michael Lykke
    0

    Hi Tim

    Thanks, that did the trick! Great!

    I'll keep an eye out for the next release for the fix regarding the issue with file extensions.

    Michael

Please Sign in or register to post replies

Write your reply to:

Draft