Menu items parsed twice
Here should go questions about transforming XML with XSLT and FOP.
-
- Posts: 7
- Joined: Mon Apr 11, 2005 10:55 am
- Location: Oslo, Norway
Menu items parsed twice
I have a problem with a bit of XSLT that is parsing a submenu twice. What I need is this:
But what I'm actually getting is this:
You can see the XSLT below -- I think the problem is in the very last xsl:template, but sure I am not ... I'd appreciate your help! :)
Code: Select all
<ul id="meny">
<li><a href="">Menu 1</a></li>
<li><a href="">Menu 2</a>
<ul>
<li><a href="">Menu 2-1</a></li>
<li><a href="">Menu 2-2</a></li>
</ul>
</li>
<li><a href="">Menu 3</a></li>
</ul>
Code: Select all
<ul id="meny">
<li><a href="">Menu 1</a></li>
<li><a href="">Menu 2</a>
<ul>
<li><a href="">Menu 2-1</a></li>
<li><a href="">Menu 2-2</a></li>
</ul>
</li>
<li><a href="">Menu 2-1</a></li>
<li><a href="">Menu 2-2</a></li>
<li><a href="">Menu 3</a></li>
</ul>
Code: Select all
<?xml version='1.0'?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="html" indent="yes" encoding="ISO-8859-1"/>
<!--
==========================================================================
Start menu templates, be careful when modifying
==========================================================================
-->
<xsl:param name="PATH">
<xsl:call-template name="TRACE_FOLDER_TO_ROOT">
<!-- Specify id below to tell script what folder ID to use as basis for menu location -->
<xsl:with-param name="id" select="(//ARTICLES/ACTION/FOLDER_CONTENTS/PARENT/FOLDER/ID|//ARTICLES/ACTION/ARTICLE/FOLDER_ID)[1]"/>
</xsl:call-template>
</xsl:param>
<xsl:template name="TRACE_FOLDER_TO_ROOT">
<!-- Trace current folder ID to top folder -->
<xsl:param name="id"/>
<xsl:param name="str"/>
<xsl:variable name="parent" select="//ARTICLES//FOLDERS/FOLDER[ID=$id]/PARENT"/>
<xsl:variable name="newstr" select="concat($str, ',', $id, ',')"/>
<xsl:choose>
<xsl:when test="$parent and //ARTICLES//FOLDERS/FOLDER[ID=$parent]">
<!-- Recurse -->
<xsl:call-template name="TRACE_FOLDER_TO_ROOT">
<xsl:with-param name="id" select="$parent"/>
<xsl:with-param name="str" select="$newstr"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<!-- We're at top -->
<xsl:value-of select="$newstr"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="FOLDERS/FOLDER" mode="MENU">
<xsl:if test="not(PARENT) or contains($PATH, concat(',', PARENT, ','))">
<!-- We're either at root or have a parent in path -->
<xsl:apply-templates select="." mode="WRITE"/>
</xsl:if>
<xsl:if test="contains($PATH, concat(',', ID, ','))">
<!-- We're a parent in path -->
<xsl:variable name="myID" select="ID"/>
<xsl:apply-templates select="../FOLDER[PARENT=$myID]" mode="MENU"/>
</xsl:if>
</xsl:template>
<!--
==========================================================================
End menu templates
==========================================================================
-->
<!-- Override this to implement own content -->
<xsl:template name="MENU">
<ul id="meny">
<xsl:apply-templates select="//FOLDERS/FOLDER[DEPTH=1]" mode="MENU"/>
</ul>
</xsl:template>
<xsl:template match="FOLDERS/FOLDER[DEPTH=1]" mode="WRITE">
<li><a href="{URL}"><xsl:value-of select="NAME"/></a>
<xsl:if test="../*[PARENT = current()/ID] and contains($PATH, concat(',', ID, ','))">
<ul>
<xsl:apply-templates select="//FOLDERS/FOLDER[DEPTH=2]" mode="MENU"/>
</ul>
</xsl:if>
</li>
</xsl:template>
<xsl:template match="FOLDERS/FOLDER[DEPTH=2]" mode="WRITE">
<li><a href="{URL}"><xsl:value-of select="NAME"/></a></li>
</xsl:template>
</xsl:stylesheet>
The knuckles! The horrible knuckles!
-
- Site Admin
- Posts: 2095
- Joined: Thu Jan 09, 2003 2:58 pm
Hi,
Can you post also your input XML?
the procedure to find out the problem should be like:
1. Switch to XSLT Debugger perspective
2. Apply the transfromation
3. Click in the output on the part that is added but you do not expect it
4. Look in the XSL and XML editors and see the selection, that represents the parts that generate that output (the context in the XML editor and the XSLT code in the XSL editor)
5. If that is not enough to understand what happens set a breakpoint before or on that XSLT line and/or XML line execution and run the debugger, that may help you understand better what is going on.
Best Regards,
George
Can you post also your input XML?
the procedure to find out the problem should be like:
1. Switch to XSLT Debugger perspective
2. Apply the transfromation
3. Click in the output on the part that is added but you do not expect it
4. Look in the XSL and XML editors and see the selection, that represents the parts that generate that output (the context in the XML editor and the XSLT code in the XSL editor)
5. If that is not enough to understand what happens set a breakpoint before or on that XSLT line and/or XML line execution and run the debugger, that may help you understand better what is going on.
Best Regards,
George
Jump to
- Oxygen XML Editor/Author/Developer
- ↳ Feature Request
- ↳ Common Problems
- ↳ DITA (Editing and Publishing DITA Content)
- ↳ SDK-API, Frameworks - Document Types
- ↳ DocBook
- ↳ TEI
- ↳ XHTML
- ↳ Other Issues
- Oxygen XML Web Author
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Content Fusion
- ↳ Feature Request
- ↳ Common Problems
- Oxygen JSON Editor
- ↳ Feature Request
- ↳ Common Problems
- Oxygen PDF Chemistry
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Feedback
- ↳ Feature Request
- ↳ Common Problems
- Oxygen XML WebHelp
- ↳ Feature Request
- ↳ Common Problems
- XML
- ↳ General XML Questions
- ↳ XSLT and FOP
- ↳ XML Schemas
- ↳ XQuery
- NVDL
- ↳ General NVDL Issues
- ↳ oNVDL Related Issues
- XML Services Market
- ↳ Offer a Service