RE: [xsl] Recursively Walking Through a Heirarchy

Subject: RE: [xsl] Recursively Walking Through a Heirarchy
From: "Aron Bock" <aronbock@xxxxxxxxxxx>
Date: Fri, 06 May 2005 16:20:48 +0000
Johnathon,

You haven't specified what HTML output you want and how you want the "tab in". The following XSL, for example, will generates nested <p> elements, but you should be able to change that to tables, lists, etc.

Also, it seems customary on this list to post a small (but still complete) representative sample of the input XML, rather than an entire, repetitous document. Thus I've shortened your sample as below:

With this input:

<site_map>
   <category>
       <category_id>13</category_id>
       <category_name>Massage Tables</category_name>
       <URL>/categories/Massage-Tables/13/1</URL>

       <category>
           <category_id>91</category_id>
           <category_name>Massage Table Packages</category_name>
           <URL>/categories/Massage-Table-Packages/91/1</URL>
       </category>

       <category>
           <category_id>16</category_id>
           <category_name>Salon Center</category_name>
           <URL>/categories/Salon-Center/16/1</URL>

           <category>
               <category_id>176</category_id>
               <category_name>Paraffin Bath</category_name>
               <URL>/categories/Paraffin-Bath/176/1</URL>
           </category>

           <category>
               <category_id>177</category_id>
               <category_name>Spa Supplies</category_name>
               <URL>/categories/Spa-Supplies/177/1</URL>
           </category>
       </category>
   </category>
</site_map>

This XSL:

<?xml version="1.0" encoding="iso8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
<xsl:output method="html"/>


   <xsl:template match="category">
       <div style="padding-left:20px;">
           <xsl:value-of select="category_name"/><br/>
           <xsl:apply-templates select="category"/>
       </div>
   </xsl:template>
</xsl:stylesheet>

Produces this output:

<div style="padding-left:20px;">Massage Tables<br>
 <div style="padding-left:20px;">Massage Table Packages<br>
 </div>
 <div style="padding-left:20px;">Salon Center<br>
   <div style="padding-left:20px;">Paraffin Bath<br>
   </div>
   <div style="padding-left:20px;">Spa Supplies<br>
   </div>
 </div>
</div>

Regards,

--A


From: "Johnathon Wright" <jw@xxxxxxxxxxxxx>
Reply-To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
To: <xsl-list@xxxxxxxxxxxxxxxxxxxxxx>
Subject: [xsl] Recursively Walking Through a Heirarchy
Date: Fri, 6 May 2005 10:55:52 -0500

I have the category tree for our online store below. I need to display the
categories such that sub-categories will appear beneath and to the right of
their parent category. (and their sub categories beneath and to the right of
them... and so on down the line.) Once this is accomplished, we will use it
to show which categories a product belongs to, and to add it to other
categories.


This code walks through the categories, but does not "tab in"...

<xsl:for-each select="/configuration/site_map/category">
 <xsl:apply-template select="descendant-or-self::category">
  <ul>
   <li><xsl:value-of select="category_name" /></li>
  </ul>
 </xsl:apply-template>
</xsl:for-each>

I am easily able to get the desired effect from PHP, but my knowledge of XSL
is less advanced. Any help would be appreciated!




The XML:

<site_map>

<category>
<category_id>13</category_id>
<category_name>Massage Tables</category_name>
<URL>/categories/Massage-Tables/13/1</URL>

<category>
<category_id>91</category_id>
<category_name>Massage Table Packages</category_name>
<URL>/categories/Massage-Table-Packages/91/1</URL>
</category>

<category>
<category_id>103</category_id>
<category_name>Portable Massage Tables</category_name>
<URL>/categories/Portable-Massage-Tables/103/1</URL>
</category>

<category>
<category_id>105</category_id>
<category_name>Stationary Massage Tables</category_name>
<URL>/categories/Stationary-Massage-Tables/105/1</URL>
</category>

<category>
<category_id>100</category_id>
<category_name>MassageKing Branded Packages</category_name>
<URL>/categories/MassageKing-Branded-Packages/100/1</URL>
</category>

<category>
<category_id>229</category_id>
<category_name>Earthgear</category_name>
<URL>/categories/Earthgear/229/1</URL>
</category>

<category>
<category_id>230</category_id>
<category_name>Golden Ratio</category_name>
<URL>/categories/Golden-Ratio/230/1</URL>
</category>

<category>
<category_id>231</category_id>
<category_name>Astra-Lite</category_name>
<URL>/categories/Astra-Lite/231/1</URL>
</category>

<category>
<category_id>232</category_id>
<category_name>Pisces Productions</category_name>
<URL>/categories/Pisces-Productions/232/1</URL>
</category>

<category>
<category_id>233</category_id>
<category_name>Chattanooga Group</category_name>
<URL>/categories/Chattanooga-Group/233/1</URL>
</category>

<category>
<category_id>234</category_id>
<category_name>HealthMark</category_name>
<URL>/categories/HealthMark/234/1</URL>
</category>

<category>
<category_id>235</category_id>
<category_name>NRG Massage</category_name>
<URL>/categories/NRG-Massage/235/1</URL>
</category>

<category>
<category_id>236</category_id>
<category_name>StrongLite</category_name>
<URL>/categories/StrongLite/236/1</URL>
</category>

<category>
<category_id>237</category_id>
<category_name>Life Gear</category_name>
<URL>/categories/Life-Gear/237/1</URL>
</category>

<category>
<category_id>238</category_id>
<category_name>Dual Treatment Tables</category_name>
<URL>/categories/Dual-Treatment-Tables/238/1</URL>
</category>
</category>

<category>
<category_id>14</category_id>
<category_name>Massage Chairs</category_name>
<URL>/categories/Massage-Chairs/14/1</URL>

<category>
<category_id>220</category_id>
<category_name>Popular</category_name>
<URL>/categories/Popular/220/1</URL>
</category>

<category>
<category_id>221</category_id>
<category_name>Desktoppers</category_name>
<URL>/categories/Desktoppers/221/1</URL>
</category>

<category>
<category_id>222</category_id>
<category_name>Earthgear</category_name>
<URL>/categories/Earthgear/222/1</URL>
</category>

<category>
<category_id>223</category_id>
<category_name>StrongLite</category_name>
<URL>/categories/StrongLite/223/1</URL>
</category>

<category>
<category_id>224</category_id>
<category_name>Massage Chair Packages</category_name>
<URL>/categories/Massage-Chair-Packages/224/1</URL>
</category>

<category>
<category_id>225</category_id>
<category_name>Golden Ratio</category_name>
<URL>/categories/Golden-Ratio/225/1</URL>
</category>

<category>
<category_id>226</category_id>
<category_name>HealthMark</category_name>
<URL>/categories/HealthMark/226/1</URL>
</category>

<category>
<category_id>227</category_id>
<category_name>Chattanooga Group</category_name>
<URL>/categories/Chattanooga-Group/227/1</URL>
</category>

<category>
<category_id>228</category_id>
<category_name>Pisces Productions</category_name>
<URL>/categories/Pisces-Productions/228/1</URL>
</category>
</category>

<category>
<category_id>15</category_id>
<category_name>Massage Supplies</category_name>
<URL>/categories/Massage-Supplies/15/1</URL>

<category>
<category_id>167</category_id>
<category_name>Pillows & Support</category_name>
<URL>/categories/Pillows-&amp;-Support/167/1</URL>

<category>
<category_id>210</category_id>
<category_name>Bolsters</category_name>
<URL>/categories/Bolsters/210/1</URL>
</category>

<category>
<category_id>211</category_id>
<category_name>Body Cushion Systems</category_name>
<URL>/categories/Body-Cushion-Systems/211/1</URL>
</category>

<category>
<category_id>212</category_id>
<category_name>Pillows</category_name>
<URL>/categories/Pillows/212/1</URL>
</category>

<category>
<category_id>213</category_id>
<category_name>Pregnancy Systems</category_name>
<URL>/categories/Pregnancy-Systems/213/1</URL>
</category>
</category>

<category>
<category_id>18</category_id>
<category_name>Creams, Lotions and Oils</category_name>
<URL>/categories/Creams,-Lotions-and-Oils/18/1</URL>

<category>
<category_id>20</category_id>
<category_name>BioFreeze</category_name>
<URL>/categories/BioFreeze/20/1</URL>
</category>

<category>
<category_id>180</category_id>
<category_name>Massage Oil</category_name>
<URL>/categories/Massage-Oil/180/1</URL>
</category>

<category>
<category_id>181</category_id>
<category_name>Massage Lotions & Creams</category_name>
<URL>/categories/Massage-Lotions-&amp;-Creams/181/1</URL>
</category>

<category>
<category_id>182</category_id>
<category_name>Pain Relief</category_name>
<URL>/categories/Pain-Relief/182/1</URL>
</category>

<category>
<category_id>183</category_id>
<category_name>Body Butters</category_name>
<URL>/categories/Body-Butters/183/1</URL>
</category>
</category>

<category>
<category_id>17</category_id>
<category_name>Sheets and Linens</category_name>
<URL>/categories/Sheets-and-Linens/17/1</URL>

<category>
<category_id>186</category_id>
<category_name>Fleece Items</category_name>
<URL>/categories/Fleece-Items/186/1</URL>
</category>
</category>

<category>
<category_id>19</category_id>
<category_name>Massage Music, Books & Video</category_name>
<URL>/categories/Massage-Music,-Books-&amp;-Video/19/1</URL>

<category>
<category_id>194</category_id>
<category_name>Music</category_name>
<URL>/categories/Music/194/1</URL>
</category>

<category>
<category_id>195</category_id>
<category_name>Books</category_name>
<URL>/categories/Books/195/1</URL>
</category>

<category>
<category_id>196</category_id>
<category_name>Videos & DVD</category_name>
<URL>/categories/Videos-&amp;-DVD/196/1</URL>
</category>
</category>

<category>
<category_id>69</category_id>
<category_name>Hot & Cold Therapy</category_name>
<URL>/categories/Hot-&amp;-Cold-Therapy/69/1</URL>

<category>
<category_id>187</category_id>
<category_name>Pain Relief Lotions & Gels</category_name>
<URL>/categories/Pain-Relief-Lotions-&amp;-Gels/187/1</URL>
</category>

<category>
<category_id>188</category_id>
<category_name>Stone Therapy</category_name>
<URL>/categories/Stone-Therapy/188/1</URL>
</category>

<category>
<category_id>189</category_id>
<category_name>Hot Packs</category_name>
<URL>/categories/Hot-Packs/189/1</URL>
</category>

<category>
<category_id>190</category_id>
<category_name>Cold Packs</category_name>
<URL>/categories/Cold-Packs/190/1</URL>
</category>

<category>
<category_id>191</category_id>
<category_name>Hot & Cold Packs</category_name>
<URL>/categories/Hot-&amp;-Cold-Packs/191/1</URL>
</category>

<category>
<category_id>192</category_id>
<category_name>Heating Units</category_name>
<URL>/categories/Heating-Units/192/1</URL>
</category>

<category>
<category_id>193</category_id>
<category_name>Chilling Units</category_name>
<URL>/categories/Chilling-Units/193/1</URL>
</category>
</category>

<category>
<category_id>165</category_id>
<category_name>Aromatherapy</category_name>
<URL>/categories/Aromatherapy/165/1</URL>
</category>

<category>
<category_id>166</category_id>
<category_name>Gift & Accessory Kits</category_name>
<URL>/categories/Gift-&amp;-Accessory-Kits/166/1</URL>
</category>

<category>
<category_id>175</category_id>
<category_name>Bolsters</category_name>
<URL>/categories/Bolsters/175/1</URL>
</category>

<category>
<category_id>95</category_id>
<category_name>Charts</category_name>
<URL>/categories/Charts/95/1</URL>
</category>

<category>
<category_id>171</category_id>
<category_name>Massage Table Accessories</category_name>
<URL>/categories/Massage-Table-Accessories/171/1</URL>

<category>
<category_id>179</category_id>
<category_name>Disposables</category_name>
<URL>/categories/Disposables/179/1</URL>
</category>

<category>
<category_id>200</category_id>
<category_name>Bolsters</category_name>
<URL>/categories/Bolsters/200/1</URL>
</category>

<category>
<category_id>201</category_id>
<category_name>Holsters</category_name>
<URL>/categories/Holsters/201/1</URL>
</category>

<category>
<category_id>202</category_id>
<category_name>Sheet Sets & Fleece</category_name>
<URL>/categories/Sheet-Sets-&amp;-Fleece/202/1</URL>
</category>

<category>
<category_id>204</category_id>
<category_name>Cloud Comfort Memory Foam</category_name>
<URL>/categories/Cloud-Comfort-Memory-Foam/204/1</URL>
</category>

<category>
<category_id>205</category_id>
<category_name>Body Cushion Systems</category_name>
<URL>/categories/Body-Cushion-Systems/205/1</URL>
</category>

<category>
<category_id>206</category_id>
<category_name>Massage Table Carry Case & Carts</category_name>
<URL>/categories/Massage-Table-Carry-Case-&amp;-Carts/206/1</URL>
</category>
</category>

<category>
<category_id>173</category_id>
<category_name>Personal Care</category_name>
<URL>/categories/Personal-Care/173/1</URL>

<category>
<category_id>217</category_id>
<category_name>Salt & Sugar Scrubs</category_name>
<URL>/categories/Salt-&amp;-Sugar-Scrubs/217/1</URL>
</category>

<category>
<category_id>218</category_id>
<category_name>Hands & Feet</category_name>
<URL>/categories/Hands-&amp;-Feet/218/1</URL>
</category>

<category>
<category_id>219</category_id>
<category_name>Facial Care</category_name>
<URL>/categories/Facial-Care/219/1</URL>
</category>
</category>

<category>
<category_id>172</category_id>
<category_name>Office & Marketing</category_name>
<URL>/categories/Office-&amp;-Marketing/172/1</URL>

<category>
<category_id>207</category_id>
<category_name>Software & Office Tools</category_name>
<URL>/categories/Software-&amp;-Office-Tools/207/1</URL>
</category>

<category>
<category_id>208</category_id>
<category_name>Cleaning Supplies</category_name>
<URL>/categories/Cleaning-Supplies/208/1</URL>
</category>

<category>
<category_id>209</category_id>
<category_name>Artwork & Posters</category_name>
<URL>/categories/Artwork-&amp;-Posters/209/1</URL>
</category>
</category>

<category>
<category_id>169</category_id>
<category_name>Therapist Care</category_name>
<URL>/categories/Therapist-Care/169/1</URL>
</category>

<category>
<category_id>168</category_id>
<category_name>Yoga & Fitness</category_name>
<URL>/categories/Yoga-&amp;-Fitness/168/1</URL>

<category>
<category_id>214</category_id>
<category_name>Everything Yoga</category_name>
<URL>/categories/Everything-Yoga/214/1</URL>
</category>

<category>
<category_id>215</category_id>
<category_name>Fitness Center</category_name>
<URL>/categories/Fitness-Center/215/1</URL>
</category>

<category>
<category_id>216</category_id>
<category_name>Inversion Tables</category_name>
<URL>/categories/Inversion-Tables/216/1</URL>
</category>
</category>

<category>
<category_id>170</category_id>
<category_name>Massage Tools</category_name>
<URL>/categories/Massage-Tools/170/1</URL>

<category>
<category_id>197</category_id>
<category_name>Manual Massage Tools</category_name>
<URL>/categories/Manual-Massage-Tools/197/1</URL>
</category>

<category>
<category_id>198</category_id>
<category_name>Electric Massage Tools</category_name>
<URL>/categories/Electric-Massage-Tools/198/1</URL>
</category>

<category>
<category_id>199</category_id>
<category_name>Stone Massage Therapy</category_name>
<URL>/categories/Stone-Massage-Therapy/199/1</URL>
</category>
</category>

<category>
<category_id>174</category_id>
<category_name>Mind, Body & Spirit</category_name>
<URL>/categories/Mind,-Body-&amp;-Spirit/174/1</URL>
</category>

<category>
<category_id>184</category_id>
<category_name>Holsters</category_name>
<URL>/categories/Holsters/184/1</URL>
</category>

<category>
<category_id>185</category_id>
<category_name>Stools</category_name>
<URL>/categories/Stools/185/1</URL>
</category>

<category>
<category_id>203</category_id>
<category_name>Massage Table Carry Case & Carts</category_name>
<URL>/categories/Massage-Table-Carry-Case-&amp;-Carts/203/1</URL>
</category>

<category>
<category_id>239</category_id>
<category_name>Pregnancy Center</category_name>
<URL>/categories/Pregnancy-Center/239/1</URL>
</category>
</category>

<category>
<category_id>16</category_id>
<category_name>Salon Center</category_name>
<URL>/categories/Salon-Center/16/1</URL>

<category>
<category_id>176</category_id>
<category_name>Paraffin Bath</category_name>
<URL>/categories/Paraffin-Bath/176/1</URL>
</category>

<category>
<category_id>177</category_id>
<category_name>Spa Supplies</category_name>
<URL>/categories/Spa-Supplies/177/1</URL>
</category>

<category>
<category_id>178</category_id>
<category_name>Salon Tables</category_name>
<URL>/categories/Salon-Tables/178/1</URL>
</category>
</category>

<category>
<category_id>243</category_id>
<category_name>Therapists' Resources</category_name>
<URL>/categories/Therapists'-Resources/243/1</URL>
</category>

<category>
<category_id>244</category_id>
<category_name>Hot, New Products</category_name>
<URL>/categories/Hot,-New-Products/244/1</URL>
</category>
</site_map>


_________________________________________________________________
Is your PC infected? Get a FREE online computer virus scan from McAfee. Security. http://clinic.mcafee.com/clinic/ibuy/campaign.asp?cid=3963


Current Thread