Copied to clipboard

Flag this post as spam?

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


  • Den Gordo 29 posts 49 karma points
    Jul 20, 2012 @ 13:45
    Den Gordo
    0

    copy of child node returns open node tag in foreach loop

    Hi, I'm using umbraco v 4.7.2 (Assembly version: 1.0.4500.21031)

    I have simplified my code to make it easier to read and understand, here is the code:

    <?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:tagsLib="urn:tagsLib" xmlns:BlogLibrary="urn:BlogLibrary" xmlns:autofolders.library="urn:autofolders.library" xmlns:youtube="urn:youtube"
      exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets tagsLib BlogLibrary autofolders.library youtube ">


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

    <xsl:param name="currentPage"/>
    <xsl:template match="/">

    <!-- here is our nodes tree -->
    <xsl:variable
    name="relations">
    <relation><node id="1"></node></relation>
    <relation><node id="2"></node></relation>
    <relation><node id="3"></node></relation>
    <relation><node id="4"></node></relation>
    <relation><node id="5"></node></relation
    </xsl:variable>

    <xsl:variable name="relationNodes" select="msxml:node-set($relations)" />

    <xsl:variable name="nodes">
    <xsl:for-each select="$relationNodes/*">
        <xsl:copy-of select="./node"/>
    </xsl:for-each>
    </xsl:variable>
      
    <xsl:copy-of select="$nodes"/>

    </xsl:template>
    </xsl:stylesheet>


    this code produces nodes in very strange format having all closing tags in the end:

    <node id="1">
      <node id="2">
        <node id="3">
          <node id="4">
            <node id="5"></node>
          </node>
        </node>
      </node>
    </node>

    But what I need is obviosly that:

    <node id="1"></node>
    <node id="2"></node>
    <node id="3"></node>
    <node id="4"></node>
    <node id="5"></node>

    What am I doing wrong?

  • Dan 1285 posts 3917 karma points c-trib
    Jul 22, 2012 @ 09:02
    Dan
    0

    Hi Denis,

    This sounds like a self-closing XML tags issue.  Try this:

    <!-- here is our nodes tree -->
    <xsl:variable name="relations">
    <relation><node id="1"><xsl:value-of select="''" /></node></relation>
    <relation><node id="2"><xsl:value-of select="''" /></node></relation>
    <relation><node id="3"><xsl:value-of select="''" /></node></relation>
    <relation><node id="4"><xsl:value-of select="''" /></node></relation>
    <relation><node id="5"><xsl:value-of select="''" /></node></relation>  
    </xsl:variable>

    It's basically just putting empty strings into the nodes to prevent them from self-closing.  There are other ways to prevent self-closing tags, but I tend to use this one as it's clear and simple and (usually!) reliable.

    I hope this resolves it anyhow...

Please Sign in or register to post replies

Write your reply to:

Draft