Copied to clipboard

Flag this post as spam?

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


  • Grant Stephen 18 posts 58 karma points
    Jul 27, 2011 @ 17:39
    Grant Stephen
    0

    nested xsl:for-each

    i am trying, unsuccssefully , to code some xslt to outpout html,

    ihave a node(publications), publication node  has 3

    Publication Node

    • pub1

    pub1 offer 1

    pub1 offer2

    pub1 offer3

    • pub2

     pub2 offer1

    pub2 offer2

    • pub3

    pub3 offer1

    what im trying to do is have the properties of each publication node show in the publication page like so
    pub1 pub2 pub3
    pub1 offer1 pub2 offer1 pub3 offer1
    pub1 offer2 pub2 offer2
    pub1 offer3
    here's my effort which, is fine apart from repeating all the offers below each publication
    <xsl:param name="currentPage"/>
        
        <xsl:variable name="subPubs" select="$currentPage/Publication"/>
        
    <xsl:template match="/">
      <xsl:for-each select="$subPubs"<!-- publication options -->
          
                <xsl:variable name="ID">
                    <xsl:choose>
                      <xsl:when test="position() = 1">sub-left</xsl:when>
                      <xsl:when test="position() = 2">sub-right</xsl:when>
                      <xsl:when test="position() = 3">sub-far-right</xsl:when>
                    </xsl:choose>
                </xsl:variable>
            <!-- get each subscription publication options -->
                <div id="{$ID}" class="subs-offer-details">
                  <h2><xsl:value-of select="./title" />
                  </h2>
                  <img src="images/blank.png" width="300" height="200" />
                  <xsl:value-of select="./description" disable-output-escaping="yes"/>
                </div>
       
        <xsl:for-each select="$subPubs/offer">
       <p<xsl:value-of select="./title" /></p>
        </xsl:for-each>
      </xsl:for-each>
       
    <!-- start writing XSLT -->

    </xsl:template>
    just starting out in xslt, any help would be appreciated,
    Grant 

     

  • Richard 146 posts 168 karma points
    Jul 27, 2011 @ 18:11
    Richard
    0

    I am just doing almost the same thing. At the moment it outputs

    <dl>
    <dt>Pub 1</dt>
    <dd>Image cropper</dd>
    <dd>Downhill Chile Mountain Bike</dd>

    <dt>Pub 2</dt>
    <dd>pub 2offer 1</dd>
    </dl>

    I have done this with, translated into new schema:

      <xsl:variable name="selectedNodes" select="$currentPage/Publication"/>

    <xsl:if test="count($selectedNodes) &gt; 0">

    <dl>
    <xsl:apply-templates select="$selectedNodes">
    <xsl:sort select="@sortOrder" order="ascending"/>
    </xsl:apply-templates>
    </dl><!-- end #children -->

    </xsl:if>

    </xsl:template>

    <xsl:template match="Publication">

    <dt><xsl:value-of select="@nodeName"/></dt>

    <!-- Now select the child nodes, change offer to NodeTypeAlias of child node -->
    <xsl:apply-templates select="./offer">
    <xsl:sort select="@sortOrder" order="ascending"/>
    </xsl:apply-templates>

    </xsl:template>

    <xsl:template match="offer">
    <dd><xsl:value-of select="@nodeName"/></dd>
    </xsl:template>

    If you are not getting quite what you expect, insert <xsl:copy-of select="."/> and it will out the XML that is being processed, view in page source.

    Richard

     

  • Grant Stephen 18 posts 58 karma points
    Jul 28, 2011 @ 14:46
    Grant Stephen
    0

    Thanks Richard,

    I now have it working to a fashion, however the output is still not quite right (below)

    what im trying to achieve is

    imty most recent script :

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

     <xsl:variable name="selectedNodes" select="$currentPage/Subscriptions"/>

      <xsl:if test="count($selectedNodes) &gt; 0">
            
        <p>
          <xsl:apply-templates select="$selectedNodes">    
            <xsl:sort select="@sortOrder" order="ascending"/>        
          </xsl:apply-templates>
        </p><!-- end #children -->
        
      </xsl:if>

    </xsl:template>

    <xsl:template match="Subscriptions">
                <xsl:variable name="ID">
                    <xsl:choose>
                      <xsl:when test="position() = 1">sub-left</xsl:when>
                      <xsl:when test="position() = 2">sub-right</xsl:when>
                      <xsl:when test="position() = 3">sub-far-right</xsl:when>
                    </xsl:choose>
                </xsl:variable>
         <!-- get each subscription publication options -->
                <div id="{$ID}" class="subs-offer-details">
                  <h2><xsl:value-of select="./subtitle" />
                  </h2>
                  <img src="images/blank.png" width="300" height="200" />
                  <xsl:value-of select="./description" disable-output-escaping="yes"/>
                </div>
       
            <!-- Now select the child nodes, change offer to NodeTypeAlias of child node -->
        <xsl:apply-templates select="./SubscriptionOption">    
            <xsl:sort select="@sortOrder" order="ascending"/>        
        </xsl:apply-templates>
            
    </xsl:template>

    <xsl:template match="SubscriptionOption">
      

      <ul>
      <li><xsl:value-of select="@nodeName"/>From  &pound;<xsl:value-of select="./price" /></li>
      </ul>

    </xsl:template>

    have tried everything i could think of...........

     

     

     

  • Richard 146 posts 168 karma points
    Jul 28, 2011 @ 15:46
    Richard
    0

    Grant,

    I expect that the SubscriptionOptions call should be inside the DIV with class subs-offer-details, like:

               <div id="{$ID}" class="subs-offer-details">
                  <h2><xsl:value-of select="./subtitle" /></h2>

                  <!-- Now select the child nodes, change offer to NodeTypeAlias of child node -->
                   <xsl:apply-templates select="./SubscriptionOption">    
                     <xsl:sort select="@sortOrder" order="ascending"/>        
                  </xsl:apply-templates>

                  <img src="images/blank.png" width="300" height="200" />
                  <xsl:value-of select="./description" disable-output-escaping="yes"/>
                </div>

     

    Richard

  • Grant Stephen 18 posts 58 karma points
    Jul 28, 2011 @ 16:15
    Grant Stephen
    0

    Richard,

    Thanks a million,it worked a treat

    Grant

  • Richard 146 posts 168 karma points
    Jul 28, 2011 @ 16:18
    Richard
    0

    Grant,

    That is good to hear.

Please Sign in or register to post replies

Write your reply to:

Draft