Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Sep 2006
    Posts
    131
    Thanks
    5
    Thanked 0 Times in 0 Posts

    XSL Stylesheet Help

    Hello,

    I'm creating a breadcrumb tool.

    Currently I'm getting:
    Name 1 > Name 2 > Name 3
    but I want to get
    Name 1 > Name 2 > Name 3 > Current Page

    Thanks for the help!

    Tony

    Code:
    <system-index-block current-time="1235615500057" name="breadcrumbs" type="folder">
       <system-folder id="ROOT">
          <name>/</name>
    
          <display-name>/</display-name>
    
          <path>//</path>
    
          <system-folder id="023ad30e80c8a8b60127f2bb75bb4341">
             <name>Name 1</name>
    
             <path>/Level1</path>
    
             <system-folder id="78726c5a80c8a8b600a10ea258fc198e">
                <name>Name 2</name>
    
                <path>/Level1/Level2</path>
    
                <system-folder current="true" id="6c68278280c8a8b6001b9c3fc643c32d">
                   <name>Name 3</name>
    
                   <path>/Level1/Level2/Level3</path>
    
                   <system-page current="true" id="6c6833bc80c8a8b6001b9c3fe310f944">
                      <name>Current Name</name>
    
                      <path>/Level1/Level2/Level3/index</path>
                   </system-page>
                </system-folder>
             </system-folder>
          </system-folder>
       </system-folder>
    </system-index-block>
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    	<xsl:output indent="yes" method="xml"/>
    
    	<xsl:template match="system-index-block">
    		<ul>
    			<xsl:apply-templates select="descendant::system-folder[descendant::system-page[@current = 'true']][count(ancestor::system-folder) > 0]"/>
    		</ul>
    	</xsl:template>
    
    	<xsl:template match="system-folder">
    
    		<li>
    			<xsl:if test="position() = 1">
    				<xsl:attribute name="class">first</xsl:attribute>
    			</xsl:if>
    			<a>
    				<xsl:attribute name="href">
    					<xsl:value-of select="system-page[name = 'index']/path"/>
    				</xsl:attribute>
    
    				<xsl:call-template name="get-name"/>
    			</a>
    		</li>
    	</xsl:template>
    	
    
    	<xsl:template name="get-name">
    		<xsl:choose>
    			<xsl:when test="display-name">
    				<xsl:value-of select="display-name"/>
    
    			</xsl:when>
    			<xsl:when test="title">
    				<xsl:value-of select="title"/>
    			</xsl:when>
    			<xsl:otherwise>
    				<xsl:value-of select="name"/>
    			</xsl:otherwise>
    		</xsl:choose>	
    	</xsl:template>
    
    </xsl:stylesheet>
    ---------
    Client / Server Side Programmer II

  • #2
    Senior Coder shyam's Avatar
    Join Date
    Jul 2005
    Posts
    1,563
    Thanks
    2
    Thanked 163 Times in 160 Posts
    you wrote this descendant::system-folder[descendant::system-page[@current = 'true']][count(ancestor::system-folder) > 0] wicked xpath and have trouble fixing that? i'm having trouble believing that

    all you need is a mundane xsl:if
    Code:
      <xsl:template match="system-folder">
    
        <li>
          <xsl:if test="position() = 1">
            <xsl:attribute name="class">first</xsl:attribute>
          </xsl:if>
          <a>
            <xsl:attribute name="href">
              <xsl:value-of select="system-page[name = 'index']/path"/>
            </xsl:attribute>
    
            <xsl:call-template name="get-name"/>
          </a>
        </li>
        <xsl:if test="count(system-page) = 1">
          <li>
            <a>
              <xsl:attribute name="href">
                <xsl:value-of select="system-page/path" />
              </xsl:attribute>
              <xsl:value-of select="system-page/name" />
            </a>
          </li>
        </xsl:if>
      </xsl:template>
    You never have to change anything you got up in the middle of the night to write. -- Saul Bellow

  • #3
    Regular Coder
    Join Date
    Sep 2006
    Posts
    131
    Thanks
    5
    Thanked 0 Times in 0 Posts
    thanks worked like a charm
    ---------
    Client / Server Side Programmer II


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •