Copied to clipboard

Flag this post as spam?

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


  • Bjarne Fyrstenborg 1284 posts 4038 karma points MVP 8x c-trib
    Aug 09, 2012 @ 09:19
    Bjarne Fyrstenborg
    0

    Add HTML5 data attributes and split textstring

    Hi..

    I'm using a jQuery slider, http://iprodev.com/2012/07/iview/ , which use HTML5 data attributes .. e.g. to link to the image e.g. data-iview:image="photos/photo1.jpg", https://github.com/iprodev/iView/blob/master/index.html

    but it gives me an error, when using semicolon in the atrribute.. how can I solve this?

    Furthermore I am using the multiple textstring datatype, http://ucomponents.codeplex.com/wikipage?title=MultipleTextstring&referringTitle=Documentation , which is included in Umbraco v. 4.8.0 to add captions..

    but now I would like to write the textstring so I both can specify caption and the coordinates and then split the data into an variable.

    I'm not sure how the best pratice would be the wrap the attrubutes.. or perhaps better to write as a xml like this for each caption in the input field:
    <caption><title>Webshop</title><data-x>600</data-x><data-y>230</data-y><data-transition>wipeRight</data-transition></caption>

    So I want to have a variable with a node-set and to access each of there values something like this:

    <xsl:for-each select="./slideCaption/values/value">
             <xsl:variable name="captions">
              <title><xsl:value-of select="normalize-space(substring-before(current(), '|'))"/></title>
                    <data-x>...</data-x>
                    <data-y>...</data-y>
                    <data-transition>...</data-transition>
             </xsl:variable>
             <xsl:variable name="captionxml" select="msxml:node-set($captions)" />
                      
             <div>
                    <xsl:attribute name="class">
                          <xsl:text>iview-caption</xsl:text>
                    </xsl:attribute>
                        
                    <xsl:attribute name="data-x">
                          <xsl:value-of select="$captionxml/data-x" />
                    </xsl:attribute>
                    <xsl:attribute name="data-y">
                          <xsl:value-of select="$captionxml/data-y" />
                    </xsl:attribute>
                    <xsl:attribute name="data-transition">
                          <xsl:value-of select="$captionxml/data-transition" />
                    </xsl:attribute>
                        
            <xsl:value-of select="$captionxml/title" />
    </div>
    </xsl:for-each>

    /Bjarne

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Aug 09, 2012 @ 09:38
    Chriztian Steinmeier
    1

    Hi Bjarne,

    Regarding the use of colon in attribute names: This is a "classic" XML thing — element and attribute names consist of a prefix and a local name, e.g., all the XSLT instructions start with "xsl:" - to generate attributes with a prefixed name, all you need to do is to declare the prefix somewhere before you use it, like at the top of the file.

    If iView doesn't give you a Namespace URI to use, feel free to make one up:

    <?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:data-iview="http://iview.com/data-attribute"
        exclude-result-prefixes="umb"
    >
    
        <xsl:output method="xml" indent="yes" omit-xml-declaration="yes" />
    
        <xsl:param name="currentPage" />
    
        <xsl:template match="/">
            <div data-iview:image="{$currentPage/umbracoFile}">
                <!-- Etc. -->
            </div>
        </xsl:template>
    
    </xsl:stylesheet>

     

    Regarding the second part - think very hard about the Umbraco side of things, e.g.: I'd much rather tab my way through 6 fields on a document, than have to remember how to input those 6 fields into the same text field with brackets and all... AND you'd have the simpler XML built for you right away, no need to split (which you have to test thoroughly).

     

    /Chriztian

  • Bjarne Fyrstenborg 1284 posts 4038 karma points MVP 8x c-trib
    Aug 09, 2012 @ 10:09
    Bjarne Fyrstenborg
    0

    Hi Chriztian

    Thanks for your help.. yes I had used these namespace URI before with facebook, addthis etv.. but didn't know about how to declare your own prefixed names. it works as intended..

    Yes, I am aware that it has to be written in a correct pattern, but the caption title and the attributes are kept in same line.. but it's a bit difficult to split the string into the right parts and there must be used a delimiter, which not occurs in e.g. the title which might contains comma.

    I think you're right about it would be better to define 6 properties and get these values.. then the only thing to keep in mind, is the position of each field.. so if I use Multiple Textstring datatype to these properties, the first value should be related to the first values in the other properties.

    /Bjarne

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Aug 09, 2012 @ 10:16
    Chriztian Steinmeier
    1

    Hi Bjarne,

    The best choice would of course be to build a custom data type for it, but I think you should check out some of the existing "compound" data types (Embedded Content, DataType Grid etc.). They're all trying to solve this kind of problem - some does it better than others, though :-)

    /Chriztian

  • Bjarne Fyrstenborg 1284 posts 4038 karma points MVP 8x c-trib
    Aug 09, 2012 @ 11:12
    Bjarne Fyrstenborg
    0

    Hi Chriztian

    I first tried with Multiple Textstring, but when mentioned Data Grid I tried it instead, which also relate title, coordinates, transitons together..

    I wrote a captions variable and could then easy access the properties..

    <xsl:variable name="captions">
    <xsl:for-each select="./slideCaption">
                      <xsl:for-each select="./items/item">
                        <caption>
                            <title><xsl:value-of select="current()/caption"/></title>
                            <data-x><xsl:value-of select="current()/captionxPos"/></data-x>
                            <data-y><xsl:value-of select="current()/captionyPos"/></data-y>
                            <data-transition><xsl:value-of select="current()/captionTransition"/></data-transition>
                        </caption>
                      </xsl:for-each>
    </xsl:for-each>
    </xsl:variable>
    <xsl:variable name="captionxml" select="msxml:node-set($captions)" />
                      
    <xsl:for-each select="$captionxml/caption">
    <div>
                        <xsl:attribute name="class">
                          <xsl:text>iview-caption</xsl:text>
                        </xsl:attribute>
                        
                        <xsl:attribute name="data-x">
                          <xsl:value-of select="./data-x" />
                        </xsl:attribute>
                        <xsl:attribute name="data-y">
                          <xsl:value-of select="./data-y" />
                        </xsl:attribute>
                        <xsl:attribute name="data-transition">
                          <xsl:value-of select="./data-transition" />
                        </xsl:attribute>
                        
                        <xsl:value-of select="./title" />
    </div>
    </xsl:for-each>

    /Bjarne

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Aug 09, 2012 @ 12:08
    Chriztian Steinmeier
    0

    Hi Bjarne,

    Cool - much better (I think :-)

    So now you don't really need the $captionxml variable anymore - you could just create a separate template for the slideCaption property and use that (if you like), something like this:

    <xsl:template match="/">
        <xsl:apply-templates select="$currentPage/slideCaption" />    
    </xsl:template>
    
    <xsl:template match="slideCaption">
        <xsl:for-each select="items/item">
            <div class="iview-caption"
                data-x="{captionxPos}"
                data-y="{captionyPos}"
                data-transition="{captionTransition}"
            >
                <xsl:value-of select="caption" />
            </div>
        </xsl:for-each>
    </xsl:template>

    That's of course entirely up to you :-)

    /Chriztian 

     

     

  • Bjarne Fyrstenborg 1284 posts 4038 karma points MVP 8x c-trib
    Aug 09, 2012 @ 13:37
    Bjarne Fyrstenborg
    0

    Hi Chriztian

    Yes, that is an idea :)

    Actually I would like to use diffent templates in the slideshow layout too... where some slides use images and other slides might contains a video, like the top example here: http://iprodev.com/iview/index2.html

    so I want to check i the property youTubeVideoId is empty, if not it should use a video template.
    and then apply the slideCaption to the video and image templates or should it be applied to template which match "/" ..?

    My xslt looks like this.

    <?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:data-iview="http://iview.com/data-attribute"
      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" 
      exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets ">


    <xsl:output method="xml" omit-xml-declaration="yes"/>

    <xsl:param name="currentPage"/>
       
    <xsl:template match="/">
      
      <xsl:variable name="slide" select="$currentPage/ancestor-or-self::root/descendant-or-self::SlideItem [string(umbracoNaviHide) != '1']"/>

        <div id="iview"><xsl:text</xsl:text>
            <xsl:for-each select="$slide">
              <xsl:if test="slideImage != ''">
                <xsl:variable name="path" select="umbraco.library:GetMedia(./slideImage, 0)" />
                <div>
                  <xsl:attribute name="data-iview:image">
                    <xsl:value-of select="$path/umbracoFile" />
                  </xsl:attribute>
                  
                    
                    <xsl:variable name="captions">
                    <xsl:for-each select="./slideCaption">
                      <xsl:for-each select="./items/item">
                        <caption>
                            <title><xsl:value-of select="current()/caption"/></title>
                            <data-x><xsl:value-of select="current()/captionxPos"/></data-x>
                            <data-y><xsl:value-of select="current()/captionyPos"/></data-y>
                            <data-transition><xsl:value-of select="current()/captionTransition"/></data-transition>
                        </caption>
                      </xsl:for-each>
                     </xsl:for-each>
                    </xsl:variable>
                    <xsl:variable name="captionxml" select="msxml:node-set($captions)" />
                      
                    <xsl:for-each select="$captionxml/caption">
                      <div>
                        <xsl:attribute name="class">
                          <xsl:text>iview-caption</xsl:text>
                        </xsl:attribute>
                        
                        <xsl:attribute name="data-x">
                          <xsl:value-of select="./data-x" />
                        </xsl:attribute>
                        <xsl:attribute name="data-y">
                          <xsl:value-of select="./data-y" />
                        </xsl:attribute>
                        <xsl:attribute name="data-transition">
                          <xsl:value-of select="./data-transition" />
                        </xsl:attribute>
                        
                        <xsl:value-of select="./title" />
                      </div>
                    </xsl:for-each>
                  
                  <xsl:text</xsl:text>
                </div>
              </xsl:if>
            
            </xsl:for-each>
        </div>
    </xsl:template>

    </xsl:stylesheet>

    But it would probably be better to use templates, so it's easy to manage different layout for each slide.
    In the template match="/" should apply-templates select the full xml for the slide variable?  

    /Bjarne

Please Sign in or register to post replies

Write your reply to:

Draft