|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
|
|
#1
|
|||
|
|||
|
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 |
|
#2
|
||||
|
||||
|
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"/> |
|
#3
|
||||
|
||||
|
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.
|
|
#4
|
|||
|
|||
|
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?
|
|
#5
|
||||
|
||||
|
did you ever get this solved?
|
|
#6
|
|||
|
|||
|
all set with this
I figured it out thanks.
|
|
#7
|
||||
|
||||
|
it really helps to post your solution for me as well as other who might see the thread.
|
|
#8
|
|||
|
|||
|
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.
|
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > XML Programming > passing XML tag as global variable within XSL StyleSheet |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|