INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Site map help

Site map help

(OP)
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="http://ws-sharpei.squid.com:81/DssPreview/IGXDynam..." 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 :/

RE: Site map help

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

RE: Site map help

(OP)
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>

RE: Site map help

Quote (tiermann)

but i need to make it happen in one template

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

Tom Morrison
Hill Country Software

RE: Site map help

I am almost certain this is not what you want, but you get almost identical results with this:

CODE --> XSLT

<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

RE: Site map help

(OP)
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 --> xslt

<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> 

RE: Site map help

Still a bit curious... Why only a single template?

Tom Morrison
Hill Country Software

RE: Site map help

(OP)
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.

RE: Site map help

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

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close