Copied to clipboard

Flag this post as spam?

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


  • Marcelino Martinez 5 posts 25 karma points
    Feb 16, 2011 @ 22:04
    Marcelino Martinez
    0

    Display a subnode

    I am trying to display a subnode using an if statement and I have ran into a road block. My code is displayed below. Please someone give me a clue.

    <?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" 
      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="/">

    <!-- The fun starts here -->

    <table>
    <xsl:for-each select="$currentPage/PolicyCategory">
        <tr>
          <th>
              <div id="{@nodeName}"><xsl:value-of select="@nodeName"/></div>
          </th>
          <th>&nbsp;</th>
          <th><class="normalfont" href="#contentsanchor">Back to Contents</a></th>
        </tr>
           <xsl:if test="count(./PolicyDocument) &gt; 0">
           <xsl:for-each select="./PolicyDocument">
                    <tr>
                       <td>&nbsp;</td>
                       <td><href="{umbraco.library:NiceUrl(@id)}"><xsl:value-of select="@nodeName"/></a></td>
                       <td><href="{umbraco.library:NiceUrl(@id)}"><xsl:value-of select="policyCode"/></a></td>
                    </tr>
              <xsl:if test="count(./PolicyForm) &gt; 0">
                
                <xsl:for-each select="./PolicyForm">
                  THIS IS A FREAKING FORM!
                </xsl:for-each>
              </xsl:if>
          </xsl:for-each>
          </xsl:if>
    </xsl:for-each>
    </table>

    </xsl:template>

    </xsl:stylesheet>

  • Marcelino Martinez 5 posts 25 karma points
    Feb 16, 2011 @ 22:06
    Marcelino Martinez
    0

    I am using umbraco v 4.5.2

  • Chriztian Steinmeier 2800 posts 8791 karma points MVP 8x admin c-trib
    Feb 16, 2011 @ 23:04
    Chriztian Steinmeier
    0

    Hi Marcelino,

    First of all - when you find yourself nesting for-each instructions like this and wrapping them in if statements, it's time to try using match templates instead - have a look at this approach:

    <?xml version="1.0" encoding="utf-8" ?>
    <xsl:stylesheet
        version="1.0"
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
        xmlns:umbraco.library="urn:umbraco.library"
        exclude-result-prefixes="umbraco.library"
    >
    
        <xsl:output method="xml" indent="yes" omit-xml-declaration="yes" />
    
        <xsl:param name="currentPage" />
    
        <xsl:template match="/">
            <table>
                <!-- Process the PolicyCategory node(s) on the current page -->
                <xsl:apply-templates select="$currentPage/PolicyCategory" />
            </table>
        </xsl:template>
    
        <!-- Template for PolicyCategory nodes -->
        <xsl:template match="PolicyCategory">
            <tr>
                <th><div id="{@nodeName}"><xsl:value-of select="@nodeName"/></div></th>
                <th>&#160;</th>
                <th><a class="normalfont" href="#contentsanchor">Back to Contents</a></th>
            </tr>
    
            <!-- Process any PolicyDocument nodes in here -->
            <xsl:apply-templates select="PolicyDocument" />
        </xsl:template>
    
        <!-- Template for PolicyDocument nodes -->
        <xsl:template match="PolicyDocument">
            <tr>
                <td>&#160;</td>
                <td><a href="{umbraco.library:NiceUrl(@id)}"><xsl:value-of select="@nodeName"/></a></td>
                <td><a href="{umbraco.library:NiceUrl(@id)}"><xsl:value-of select="policyCode"/></a></td>
            </tr>
    
            <!-- Process any PolicyForm nodes in here -->
            <xsl:apply-templates select="PolicyForm" />
        </xsl:template>
    
        <!-- Template for PolicyForm nodes -->
        <xsl:template match="PolicyForm">
            THIS IS A FREAKING FORM!
        </xsl:template>
    
    </xsl:stylesheet>

    That said - what's your exact problem - which nodes are you not seeing in the output?

    Does your content look like this: ?

    ($currentPage)
    - PolicyCategory
    -   PolicyDocument
    -     PolicyForm 
    -   PolicyDocument
    -     PolicyForm
    ... etc.

    /Chriztian

  • Marcelino Martinez 5 posts 25 karma points
    Feb 17, 2011 @ 16:19
    Marcelino Martinez
    0

    Right now I am seeing only the PolicyDocument and it doesn't show the PolicyForm. I just want to populate a list of all the PolicyDocument and PolicyForm with PolicyForm being indented. 

    I tried what you suggested but it still gives me the same output which is everything but showing the message "this is a freaking form". It should show that message if there is a PolicyForm document type and I have one file with that document type. 

    I'm going to keep researching and I appreciate the help. If you have any other suggestions feel free to let me know. Thanks again.

  • Marcelino Martinez 5 posts 25 karma points
    Feb 17, 2011 @ 16:29
    Marcelino Martinez
    0

    *but not showing the message "this is a freaking form"

  • Chriztian Steinmeier 2800 posts 8791 karma points MVP 8x admin c-trib
    Feb 18, 2011 @ 11:32
    Chriztian Steinmeier
    0

    If you're not seeing that message and there is indeed a document of that type (and it's published, double-checked casing on the Docuemnt Type *alias* and it is indeed placed inside a PolicyDocument document) there must be a discrepancy in The Force...

    But first, triple-check everything by dumping everything below PolicyCategory - in the root template ("/") insert a debug textarea:

    <xsl:template match="/">
        <textarea rows="8" cols="40">
            <xsl:copy-of select="$currentPage/PolicyCategory" />
        </textarea>
    
        <table>
            <!-- Process the PolicyCategory node(s) on the current page -->
            <xsl:apply-templates select="$currentPage/PolicyCategory" />
        </table>
    </xsl:template>

    And make sure that PolicyForm is actually available somewhere inside that chunk of XML...

    /Chriztian

  • Marcelino Martinez 5 posts 25 karma points
    Feb 18, 2011 @ 21:50
    Marcelino Martinez
    0

    Its working properly now. Thank you for all your help. I had it in the content section where the PolicyForm was under the Policy Category and not the PolicyDocument. But now that I have it underneath the PolicyDocument it is working properly. Thank you for all your help. 

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies