XML Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreXML Programming
The ASP Free website provides in-depth information on the latest developer tools available from Microsoft. Our cadre of writers, highly experienced industry experts, reveals the best ways to use established technologies as well as new and emerging technologies. Our coverage of Microsoft's development and administration technologies is among the most respected in the IT industry today.

ASP Free and Iron Speed Designer are giving away $5,500+ in FREE licenses. Iron Speed's RAD CASE toolset can save up to 80% of your coding time. One free license per week, one perpetual license per month!
Download and Activate to enter!

Intel® Graphics Performance Analyzers is a powerful tool suite for analyzing and optimizing your games, media, and graphics-intensive applications. Used by some of the best developers on the planet, Intel GPA lets you maximize your app’s performance.


Tutorials
| Forums

Download to Enter
| Contest Rules

DOWNLOAD INTEL® GPA FOR FREE

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old July 17th, 2003, 05:23 PM
radostan radostan is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 6 radostan User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Question passing XML tag as global variable within XSL StyleSheet

Hi everyone. I'm new to ultrashock, and I am unfamiliar to the environment, and I was hoping I could turn to some of the shockers with XML/XSL experience. I am running into quite a predicament with publishing some XML and trying to use global variables. I am trying to grab the name of the tag and pass it to other templates as a global (dynamically, since i'm trying to reuse my stylesheet for numerous XML files). for example in the code below, i am trying to create an HTML table with 'person' in the table heading, and then have the attributes contents follow in the table as well.

------------------------------------------------------------------------------------
XML code:
------------------------------------------------------------------------------------
<recordset>
<person>
<name>Stan</name>
<address>2000 Commonwealth Ave.</address>
<phone>6173276627</phone>
</person>
<person>
<name>Dany</name>
<address>360 Huntington Ave.</address>
<phone>6175846627</phone>
</person>
<person>
<name>Dennis</name>
<address>135 Beacon Street.</address>
<phone>6177108827</phone>
</person>
</recordset>

------------------------------------------------------------------------------------
XSL code:
------------------------------------------------------------------------------------
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">

<xslutput method="html" indent="yes" />

<!--Global variable declaration-->

<xsl:template match="recordset">
<table cellpading="1" border="2" width="100%">
<tr>
<td align="LEFT" valign="TOP" bgcolor="#ff9d9d"><b><font size="3" color="#000000" face="Times New Roman"><!--<xsl:value-of select="name(.)"/>--> Person (Other numerous Attributes) Information </font></b></td>
</tr>
</table>
<table cellpadding="1" width="100%" border="2" bgcolor="ffffff" summary="Valid Values">
<thead>
<tr>
<th bgcolor="#64b1ff"><FONT SIZE="2" FACE="Times New Roman" COLOR="#000000">name</FONT></th>
<th bgcolor="#64b1ff"><FONT SIZE="2" FACE="Times New Roman" COLOR="#000000">address</FONT></th>
<th bgcolor="#64b1ff"><FONT SIZE="2" FACE="Times New Roman" COLOR="#000000">phone</FONT></th>
</tr>
</thead>
<xsl:apply-templates select="person"/>
</table>
</xsl:template>

<xsl:template match="person">
<tr>
<xsl:for-each select="*">
<td><xsl:value-of select="."/></td>
</xsl:for-each>

</tr>
</xsl:template>

</xsl:stylesheet>
------------------------------------------------------------------------------------

Q: How can I actually define and pass a global (xml tag name = 'person') variable throughout the stylesheets from one template to another? Is this accomplishable at all in the context that it is in right now? Thanks in advance Shockers.

desired look:person.html

Reply With Quote
  #2  
Old July 21st, 2003, 12:07 PM
mrusaw's Avatar
mrusaw mrusaw is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Location: Dallas, Texas
Posts: 138 mrusaw User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 9
Send a message via AIM to mrusaw Send a message via Yahoo to mrusaw
I may be misunderstanding what you need but it seems like declaring a variable at the top of your page is what you need (outside any template). Anytime you declare a variable within a template it is localized to that template. Then select the variables in your templates underneath. I hope this was inline with what you needed.

Code:
<xsl:variable name="name" select="person/name"/>
<xsl:variable name="address" select="person/address"/>

Reply With Quote
  #3  
Old July 21st, 2003, 12:29 PM
mrusaw's Avatar
mrusaw mrusaw is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Location: Dallas, Texas
Posts: 138 mrusaw User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 9
Send a message via AIM to mrusaw Send a message via Yahoo to mrusaw
Also as far as i know variables are only available to the document in which they reside. Global = entire document or Local = specific region they are used.

Reply With Quote
  #4  
Old July 21st, 2003, 03:12 PM
radostan radostan is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 6 radostan User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Lightbulb

i am familiar with the declaration part, what i'm having trouble with is declaring exactly what I need to use withing the stylesheet. The desired global would contain the name of an XML tag, or 'person'. WHats the appropriate way to declare a variable like this one?

Reply With Quote
  #5  
Old July 29th, 2003, 11:23 AM
mrusaw's Avatar
mrusaw mrusaw is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Location: Dallas, Texas
Posts: 138 mrusaw User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 9
Send a message via AIM to mrusaw Send a message via Yahoo to mrusaw
did you ever get this solved?

Reply With Quote
  #6  
Old July 29th, 2003, 11:35 AM
radostan radostan is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 6 radostan User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
all set with this

I figured it out thanks.

Reply With Quote
  #7  
Old July 29th, 2003, 11:38 AM
mrusaw's Avatar
mrusaw mrusaw is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Location: Dallas, Texas
Posts: 138 mrusaw User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 9
Send a message via AIM to mrusaw Send a message via Yahoo to mrusaw
it really helps to post your solution for me as well as other who might see the thread.

Reply With Quote
  #8  
Old July 29th, 2003, 12:08 PM
radostan radostan is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 6 radostan User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
solution

well, what I did is figure out how to change the sequence of XML tags in my conversion from the database, but the XSL remains the same. THe new XML has the name of the field as the the outer most tag, so it is grabbed in the title header with the <xsl:value-of select="name(.)"/>. I'm using DataJunction for the transform, and it allows to change the layout of the XML.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreXML Programming > passing XML tag as global variable within XSL StyleSheet


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.

© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 2 - Follow our Sitemap