match pattern for xslt navigation? Options
steve.lorimer
Posted: Wednesday, September 03, 2008 11:11:51 PM
Rank: Newbie

Joined: 9/3/2008
Posts: 2
Location: London
Hi all

I'm looking for either a match pattern, or a select statement which will allow me to restrict the node set.

I have the following document_type structure:

Code:
</>
    <dt_A> a1
        <dt_B> b1
        <dt_A> a2
            <dt_B> b2
            <dt_C> c1
        <dt_B> b3
    <dt_C> c2

What I want is when $currentPage is anything below node a1 (of type dt_A), then to show my xslt navigation (code below)

ie: If I'm on node a2, then prev=b1 and next=b3
However, if I'm on node a1, then don't show prev or next

At the moment I can't figure out how to restrict my node set! :-(

Here is my xslt:
Code:

<?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"
    exclude-result-prefixes="msxml umbraco.library">

<xsl:output method="xml" omit-xml-declaration="yes"/>
<xsl:param name="currentPage"/>

<!-- this matches all nodes, which it too much! -->
<xsl:template match="/">

<!-- this doesn't match anything, but I'm looking for all children of 'Preparation' node-->
<!--
    <xsl:template match="/*[@nodeName = 'Preparation']/*">
-->

<table cellpadding="0" cellspacing="0" border="0" width="100%">
  <tr>
    <td align="left">
      <xsl:for-each select="$currentPage/preceding-sibling::node">
        <xsl:if test="@sortOrder=$currentPage/@sortOrder - 1
                      and
                      string(data [@alias='umbracoNaviHide']) != '1'">
          <a href="{umbraco.library:NiceUrl(@id)}">
            &lt;&lt;&nbsp;<xsl:value-of select="data [@alias = 'PageTitle']"/>
          </a>
        </xsl:if>
      </xsl:for-each>
    </td>

    <td align="right">
      <xsl:for-each select="$currentPage/following-sibling::node">
        <xsl:if test="@sortOrder=$currentPage/@sortOrder + 1
                      and
                      string(data [@alias='umbracoNaviHide']) != '1'">
          <a href="{umbraco.library:NiceUrl(@id)}">
            <xsl:value-of select="data [@alias = 'PageTitle']"/>&nbsp;&gt;&gt;
          </a>
        </xsl:if>
      </xsl:for-each>     
    </td>
  </tr>
</table>

</xsl:template>
</xsl:stylesheet>


Thanks!
Steve
steve.lorimer
Posted: Wednesday, September 03, 2008 11:32:01 PM
Rank: Newbie

Joined: 9/3/2008
Posts: 2
Location: London
I fixed it by using the following in my if test:

Code:
<!-- 1234 = "MyParentNode" -->
<xsl:variable name="id" select="1234"/>

<xsl:if test=contains(@path,$id)">


Here's the full code:

Code:

<?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"
    exclude-result-prefixes="msxml umbraco.library">

<xsl:output method="xml" omit-xml-declaration="yes"/>
<xsl:param name="currentPage"/>

<!-- 1234 = "MyParentNode" -->
<xsl:variable name="id" select="1234"/>

<xsl:template match="/">

<table cellpadding="0" cellspacing="0" border="0" width="100%">
  <tr>
    <td align="left">
      <xsl:for-each select="$currentPage/preceding-sibling::node">
        <xsl:if test="@sortOrder=$currentPage/@sortOrder - 1
                      and
                      string(data [@alias='umbracoNaviHide']) != '1'
                      and
                      contains(@path,$id)">
          <a href="{umbraco.library:NiceUrl(@id)}">
            &lt;&lt;&nbsp;<xsl:value-of select="data [@alias = 'PageTitle']"/>
          </a>
        </xsl:if>
      </xsl:for-each>
    </td>

    <td align="right">
      <xsl:for-each select="$currentPage/following-sibling::node">
        <xsl:if test="@sortOrder=$currentPage/@sortOrder + 1
                      and
                      string(data [@alias='umbracoNaviHide']) != '1'
                      and
                      contains(@path,$id)">
          <a href="{umbraco.library:NiceUrl(@id)}">
            <xsl:value-of select="data [@alias = 'PageTitle']"/>&nbsp;&gt;&gt;
          </a>
        </xsl:if>
      </xsl:for-each>     
    </td>
  </tr>
</table>

</xsl:template>
</xsl:stylesheet>


Users browsing this topic
Guest


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.