Copied to clipboard

Flag this post as spam?

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


  • matjohnson 7 posts 26 karma points
    Nov 05, 2011 @ 14:41
    matjohnson
    0

    Adding attributes using XSL

    I've used XSL in .Net for a while now. I'm trying to view a media folder, which works and I can get the item and view the URL, however, when I try and display it as an html element it says

    Error parsing XSLT file: \xslt\Gallery.xslt
    Here is my xsl:
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp "&#x00A0;"> ]>
    <xsl:stylesheet
     version="1.0"
     xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
     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:Exslt.ExsltSets="urn:Exslt.ExsltSets" xmlns:CWS.Twitter="urn:CWS.Twitter"
     exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets CWS.Twitter ">

    <xsl:output method="xml" omit-xml-declaration="yes"/>
    <xsl:param name="currentPage"/>
    <xsl:variable name="mediaFolderId" select="number($currentPage/mediaFolderId)" />
    <xsl:variable name="thumbWidth" select="number(256)" />
    <xsl:variable name="thumbHeight" select="number(170)" />
    <xsl:template match="/">
            <xsl:if test="number($mediaFolderId)">  
                <ul id="gallery">
                    <xsl:for-each select="umbraco.library:GetMedia($mediaFolderId, true())/Image">
      <xsl:variable name="picFile" select="umbracoFile"/>
                        <xsl:if test="umbracoFile !=''">
       <li>
       <xsl:element name="a">           
        <xsl:attribute name="href">
         <xsl:value-of select="./umbracoFile" />
        </xsl:attribute>
       </xsl:element>
       </li> 
      </xsl:if>
      </xsl:for-each>
           </ul>
     </xsl:if>
    </xsl:template>
    </xsl:stylesheet>

     

    Why can't I do:

    <xsl:element name="a">            
        <xsl:attribute name="href">
         <xsl:value-of select="./umbracoFile" />
        </xsl:attribute>
       </xsl:element>

    to show an element? If I just do the <xsl:value-of select="./umbracoFile"/> I get

    • ~/media/361/more-view-thumbnail_1.jpg

    SoI know the element is there, I just can't build it (Umbraco in the back end doesn't show any validation errors either)

    Any pointers would be great.

  • Bert 128 posts 251 karma points
    Nov 05, 2011 @ 15:17
    Bert
    0

    Seems like your code should work. Tried saving it wihtout checking for errors?
    You can always try:

                <a>
                  <xsl:attribute name="href">  
                    <xsl:value-of select="./UmbracoFile" />
                  </xsl:attribute>
                 LinkText
               
    </a>
  • matjohnson 7 posts 26 karma points
    Nov 05, 2011 @ 15:40
    matjohnson
    0

    Weird, I've done a substring to get rid of the ~ symbol, and its working now. How odd.

  • Dan Okkels Brendstrup 101 posts 197 karma points
    Nov 09, 2011 @ 10:21
    Dan Okkels Brendstrup
    1

    For the record, if you're simply outputting data, this syntax is simpler:

    <a href="{umbracoFile}">LinkText</a>
Please Sign in or register to post replies

Write your reply to:

Draft