Copied to clipboard

Flag this post as spam?

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


  • Bram Loquet 72 posts 102 karma points
    Mar 26, 2010 @ 09:49
    Bram Loquet
    0

    Looping through all values of a propertyTypePickerMultiple in XSLT

    I'm using a propertyTypePickerMultiple as Macro Paramater,
    but how do I split all these properties so that I can get the values of these properties?

  • Kim Andersen 1447 posts 2196 karma points MVP
    Mar 26, 2010 @ 10:09
    Kim Andersen
    0

    Hi Bram

    I can't remember xich character that seperates the values, but maybe you could something like this:

    <xsl:variable name="ids" select="concat(macro/propertyTypePickerMultiple,',')"/>

    <xsl:variable name="split" select="umbraco.library:Split($ids, ',')"/>

    I used something like this earlier, when I used the multipleContentPicker, where the id's where seperated by commas. You could try to write out the $split to see how the values are split up in some fine XML.

    /Kim A

     

  • Bram Loquet 72 posts 102 karma points
    Mar 26, 2010 @ 10:20
    Bram Loquet
    0

    Thanks Kim,

    How do I loop through the items of 'split now?

    <xsl:for-each select="$split">
    <xsl:value-of select="$split"/><br />
    </xsl:for-each>

    this returns just the whole string all the items

  • Fergus Davidson 309 posts 588 karma points
    Mar 26, 2010 @ 10:23
    Fergus Davidson
    0

    try:

    <xsl:for-each select="$split/value">
  • Kim Andersen 1447 posts 2196 karma points MVP
    Mar 26, 2010 @ 10:28
    Kim Andersen
    1

    Try this:

    <xsl:template match="/">  
    <xsl:variable
    name="ids" select="concat(macro/propertyTypePickerMultiple,',')"/>

    <xsl:variable name="split" select="umbraco.library:Split($ids, ',')"/>
    <xsl:apply-templates select="$split//value" />
    </xsl:template>


    <xsl:template match="value">
    <xsl:variable name="itm" select="umbraco.library:GetXmlNodeById(.)"/>
    ...
    ...
    </xsl:template>

    In the new template, we can make a new variable called $itm. This variable should contain the XML from the node with the right id. And the template will be looped for every id in your $split. A good idea is to make a textarea and print out the $itm, to check that it contains the right XML. Like this:

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

    This textarea shall of course be placed inside the <xsl:template match="value">

    Does it make sense?

    /Kim A

  • Bram Loquet 72 posts 102 karma points
    Mar 26, 2010 @ 10:30
    Bram Loquet
    0

    nice bl_ndp_lot but that return only the first item.

    It use thes properties:

    the properties: siteDescription, siteName, pageAlt, pageTitle

    and I get this response:

    - siteDescription
    - siteDescription
    - siteDescription
    - siteDescription
    - siteDescription

    with this XSLT

    the properties: <xsl:value-of select="$properties"/><br />
    <xsl:variable name="ids" select="concat(macro/properties,',')"/>
    <xsl:variable name="split" select="umbraco.library:Split($ids, ',')"/>

    <xsl:for-each select="$split/value">
    - <xsl:value-of select="$split/value"/><br />
    </xsl:for-each>
  • Bram Loquet 72 posts 102 karma points
    Mar 26, 2010 @ 10:40
    Bram Loquet
    0

    except of the fact that I return now 5 value (the for values I selected + one empty one) the solution of Kim works

     

  • Kim Andersen 1447 posts 2196 karma points MVP
    Mar 26, 2010 @ 10:45
    Kim Andersen
    0

    Sounds great Bram.

    Actually you can use another selection in your apply-templates, to make sure that you're not looping trhough the empty <value>-tag at the end. Try this one instead:

    <xsl:apply-templates select="$split//value[./text() != '' and umbraco.library:GetXmlNodeById(./text())/@nodeName != '']"/>

    Your other template should still match "value", so no change there.

    Glad I could help :)

    /Kim A

Please Sign in or register to post replies

Write your reply to:

Draft