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> </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> </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?
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.
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...
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.
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.
I am using umbraco v 4.5.2
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:
That said - what's your exact problem - which nodes are you not seeing in the output?
Does your content look like this: ?
/Chriztian
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.
*but not showing the message "this is a freaking form"
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:
And make sure that PolicyForm is actually available somewhere inside that chunk of XML...
/Chriztian
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.
is working on a reply...