Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > XSL transformation

XSL transformation
Thread Tools
Fresh-Faced Recruit
Join Date: Apr 2005
Location: Mpls, MN
Status: Offline
Reply With Quote
Apr 25, 2005, 01:59 PM
 
I've been stuck on this for a while...

I've got this XML:
Code:
<admin_panel> ... <content> // anything could be in here </content> </admin_panel>
Within the content tag could be any well formed XHTML with intermixed <action/> tags at arbitrary depths.

I want to copy the contents of the content node and then apply a template to all <action/> tags that are within.

I can't figure it out...Either I get a copy of the content node or I just get the templates applied to the <action/> tags. Here is my XSL:

Code:
<xsl:template match="content"> <div id="admpnl_content"> <xsl:copy-of select="." /> </div> </xsl:template> <xsl:template match="//action"> <a> <xsl:attribute name="href">?app=<xsl:value-of select="//app_gui"/>&amp;<xsl:value-of select="."/></xsl:attribute> <xsl:value-of select="@name"/> </a> </xsl:template>
The above XSL only returns a copy-of the content node and does not apply the template to the action tags. Any help would be much appreciated.

Thus, creating the most ginormous can of whoop ass the world as ever seen.
     
MacAtak  (op)
Fresh-Faced Recruit
Join Date: Apr 2005
Location: Mpls, MN
Status: Offline
Reply With Quote
Apr 25, 2005, 02:14 PM
 
Oh man, I figured it out!

Here's the XSL:

Code:
<xsl:template match="content"> <div id="admpnl_content"> <xsl:copy> <xsl:apply-templates /> </xsl:copy> </div> </xsl:template> <xsl:template match="*"> <xsl:copy> <xsl:apply-templates /> </xsl:copy> </xsl:template> <xsl:template match="action"> <a> <xsl:attribute name="href">?app=<xsl:value-of select="//app_gui"/>&amp;<xsl:value-of select="."/></xsl:attribute> <xsl:value-of select="@name"/> </a> </xsl:template>

Thus, creating the most ginormous can of whoop ass the world as ever seen.
     
MacAtak  (op)
Fresh-Faced Recruit
Join Date: Apr 2005
Location: Mpls, MN
Status: Offline
Reply With Quote
Apr 25, 2005, 03:10 PM
 
In case anyone is interested here is the final XSL. The above XSL kept the <content> and <admin_panel> tags and did not copy over any attributes, unlike the following which is exactly what I wanted.

Code:
<xsl:template match="*"> <xsl:copy> <xsl:copy-of select="@*"/> <xsl:apply-templates /> </xsl:copy> </xsl:template> <xsl:template match="admin_panel"> <xsl:apply-templates /> </xsl:template> <xsl:template match="content"> <div id="content"> <xsl:apply-templates /> </div> </xsl:template> <xsl:template match="action"> <a> <xsl:attribute name="href">?app=<xsl:value-of select="//app_gui"/>&amp;<xsl:value-of select="."/></xsl:attribute> <xsl:value-of select="@name"/> </a> </xsl:template>

Thus, creating the most ginormous can of whoop ass the world as ever seen.
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 07:27 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2