Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Site map help

Status
Not open for further replies.

tiermann

Programmer
Nov 12, 2013
10
US
Hello i am a beginner with xslt and am trying to create a HTML site map from a xml file. just trying to use the URL and Page Title.

<?xml version="1.0" ?>

<HTMLSiteMap ID="x4153" Name="HTML Site Map" Layout="default.xsl" IsComponent="false" SURL=" SiteBaseUrl="" Locale="" XPowerPath="/Site Folder/Site Map HTML/HTML Site Map">
<IGX_Categories Count="0" CategoryIds="" />
-
<Navigation Type="Children" Name="HTMLSiteMap" label="HTMLSiteMap">
<Page ID="x672" URL="x672.xml?Preview=true&Site=&IncludeAllPages=false&tfrm=4&PubTgt=3&Site=&UserAgent=" Schema="NewsandEvents" Locale="" Changed="20131112T15:27:12" CategoryIds="" PageTitle="News + Events TEST" Name="News and Events" />
<Page ID="x786" URL="x786.xml?Preview=true&Site=&IncludeAllPages=false&tfrm=4&PubTgt=3&Site=&UserAgent=" Schema="T21ColThumbs" Locale="" Changed="20130507T20:34:35" CategoryIds="" AbstractMedium="Medium" PageTitle="Institutes + Centers" Name="Institutes and Centers" />
<Page ID="x1065" URL="x1065.xml?Preview=true&Site=&IncludeAllPages=false&tfrm=4&PubTgt=3&Site=&UserAgent=" Schema="T1LgPhoto3ColNoThumbs" Locale="" Changed="20131106T20:41:58" CategoryIds="268" PageTitle="Alumni" Priority=".7" Name="Alumni" />
<Page ID="x1067" URL="x1067.xml?Preview=true&Site=&IncludeAllPages=false&tfrm=4&PubTgt=3&Site=&UserAgent=" Schema="T1LgPhoto3ColNoThumbs" Locale="" Changed="20130624T16:24:03" CategoryIds="" PageTitle="Parents" Priority=".5" Name="Parents" />
<Page ID="x1133" URL="x1133.xml?Preview=true&Site=&IncludeAllPages=false&tfrm=4&PubTgt=3&Site=&UserAgent=" Schema="Folder" Locale="" Changed="20120925T13:42:38" CategoryIds="" Name="Careers Site" />
<Page ID="x835" URL="x835.xml?Preview=true&Site=&IncludeAllPages=false&tfrm=4&PubTgt=3&Site=&UserAgent=" Schema="StandardPage" Locale="" Changed="20131004T13:40:44" CategoryIds="" PageTitle="squid G.A.M.E. III Forum" Name="G.A.M.E. Forum" />
<Page ID="x22" URL="x22.xml?Preview=true&Site=&IncludeAllPages=false&tfrm=4&PubTgt=3&Site=&UserAgent=" Schema="QYou" Locale="" Changed="20131101T16:23:13" CategoryIds="256|254|253|251|252|255|260|261|262" PageTitle="Q-You" Name="Q You" />
<Page ID="x67" URL="x67.xml?Preview=true&Site=&IncludeAllPages=false&tfrm=4&PubTgt=3&Site=&UserAgent=" Schema="Folder" Locale="" Changed="20121002T15:33:07" CategoryIds="" Name="Category-Theme Landing Pages" />
<Page ID="x203" URL="x203.xml?Preview=true&Site=&IncludeAllPages=false&tfrm=4&PubTgt=3&Site=&UserAgent=" Schema="Folder" Locale="" Changed="20120906T16:07:47" CategoryIds="" Name="Category-Theme Stories" />
<Page ID="x102" URL="x102.xml?Preview=true&Site=&IncludeAllPages=false&tfrm=4&PubTgt=3&Site=&UserAgent=" Schema="Folder" Locale="" Changed="20121001T00:54:13" CategoryIds="" Name="SPOTLIGHTS" />
<Page ID="x715" URL="x715.xml?Preview=true&Site=&IncludeAllPages=false&tfrm=4&PubTgt=3&Site=&UserAgent=" Schema="Folder" Locale="" Changed="20121008T19:17:28" CategoryIds="" Name="Footer Pages (liability/privacy/about site)" />
</Navigation>

</HTMLSiteMap>

help me :/
 
Happy to help, but it is a bit difficult to discern (1) what you have already tried, and (2) what your desired output might look like.

Tom Morrison
Hill Country Software
 
I am trying to create a HTML site map from this information. I've been trying to pull out the data in HTMLSiteMap. but for some reason can't seem to figure out how to do so. i know there is a way to do it with out having to do a for loop. i'm just not sure how. I was able to do it with the code below, but i need to make it happen in one template and i'm kinda stuck.

<xsl:template match="/">


<ul>
<xsl:apply-templates select="$nav//Page[@Schema!='Folder' and not(contains(@Schema, 'Component'))]"/>
</ul>

</xsl:template>

<xsl:template match="Page">
<xsl:variable name="depth" select="count(ancestor::*)"/>
<xsl:if test="@PageTitle!=''">
<xsl:choose>
<xsl:when test="$depth=2">
<xsl:variable name="rowcount"><xsl:number/></xsl:variable>

<li><a href="{@URL}"><xsl:value-of select="@PageTitle"/></a></li>

</xsl:when>
<xsl:when test="$depth=3">
<ul>
<li><a href="{@URL}"><xsl:value-of select="@PageTitle"/></a></li>
</ul>
</xsl:when>
</xsl:choose>


</xsl:if>
</xsl:template>
 
tiermann said:
but i need to make it happen in one template

Why is this a requirement? It certainly seems unusual...

Tom Morrison
Hill Country Software
 
I am almost certain this is not what you want, but you get almost identical results with this:
Code:
<xsl:template match="Page[@Schema!='Folder' and not(contains(@Schema, 'Component'))]">
<xsl:variable name="depth" select="count(ancestor::*)"/> 
<xsl:if test="@PageTitle!=''">
<xsl:choose>
<xsl:when test="$depth=2">
<xsl:variable name="rowcount"><xsl:number/></xsl:variable>

<li><a href="{@URL}"><xsl:value-of select="@PageTitle"/></a></li> 

</xsl:when>
<xsl:when test="$depth=3">
<ul>
<li><a href="{@URL}"><xsl:value-of select="@PageTitle"/></a></li>
</ul>
</xsl:when>
</xsl:choose>


</xsl:if>
</xsl:template>

Now this allows some 'seepage' due to the built-in template rules, but it is just one template.

I still seem to think that a better problem description is needed.

Tom Morrison
Hill Country Software
 
Thanks, Tom. I appreciate your help :)

I was able to get it into the list but just had to add a for loop. seemed to work well! my boss was happy :)
thanks again!

Code:
	<xsl:template match="SiteMapHTML">
					<xsl:for-each select="//Navigation[@Name='HTMLSiteMap']//Page">
					
						<xsl:variable name="depth" select="count(ancestor::*)"/>
						<xsl:if test="@PageTitle!=''"> 
							<xsl:choose>
								<xsl:when test="$depth=2">  <!--  Neat it a main node -->
									<li><a href="{@URL}"><xsl:value-of select="@PageTitle"/></a></li>
								</xsl:when>
								<xsl:when test="$depth=3">  <!-- sub node -->
									<ul>
										<li><a href="{@URL}"><xsl:value-of select="@PageTitle"/></a></li>
									</ul>
								</xsl:when>
							</xsl:choose>
						</xsl:if>
					</xsl:for-each>

	</xsl:template>
 
Still a bit curious... Why only a single template?

Tom Morrison
Hill Country Software
 
well the system that we are using has a massive stylesheet. they want to put everything in one stylesheet. and i'm trying to keep it as compact as possible.
 
Ah, I see. There are techniques for breaking stylesheets into more manageable pieces, but you don't see many tutorials on that. And, it is difficult to retrofit a big project, when there are more important things to get done.

I have worked, in a 'previous lifetime', on a big DITA project that had huge XSLTs, and it was a bit difficult keeping up with all the templates. It doesn't help that template order within the stylesheet can act as one of the tiebreakers when determining which template to apply.

One thing that I have found useful is to use the template mode attribute to isolate functionality in an otherwise chaotic XSLT. It helps connect the xsl:apply-templates to the matching templates for the maintenance programmer, and can reduce complexity in some circumstances by eliminating xsl:if and xsl:choose being used to determine different modes within templates.

So, it is a balancing act. When possible, I prefer to use template matching rather than procedural code (xsl:for-each). (Like most procedural programmers, I did not start out with this preference.) I end up with more templates, but my templates tend to be short and to the point of processing a single node. I let the recursive descent XSLT processing model do a lot of the work that way.

Welcome to Tek-Tips. Please come back again!

Tom Morrison
Hill Country Software
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top