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

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 27th, 2004, 02:32 PM
tajmiester tajmiester is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Location: Ye Olde England
Posts: 80 tajmiester User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
XSL Stylesheet advice

Hi,

I have decided to design my website using xml and then parse it with an xsl stylesheet. I have started writing the stylesheet but have a question. I wish to simply the use of html form elements on my webpages and so have created three elements (as of yet) "editbox", "submitbutton" and "inputtable". editbox includes a name and precedes the textbox with this name automatically.

I am currently working on the inputtable. I want the inputtable to contain rows of different inputs like editboxes submitbuttons all in a table so that everything is aligned. How can I iterate through each node in the inputtable and apply its template so that the node's template knows it is in a table and reacts accordingly?

Code:
so that this xml

<editbox>
<name>A box</name>
</editbox>

produces

A box: <input type="text"/>

but this xml

<inputtable>
<editbox>
<name>A box</name>
</editbox>
<editbox>
<name>Another box</name>
</editbox>
</inputtable>

produces

<table>
<td>
<td>A box:</td>
<td><input type="text"/></td>
</tr>
<td>
<td>Another box:</td>
<td><input type="text"/></td>
</tr>
</table>


Thanks in advance.

Tris
__________________
Thanx Tajmiester.

Reply With Quote
  #2  
Old July 27th, 2004, 03:38 PM
Malinali Malinali is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Location: Buenos Aires, Argentina
Posts: 74 Malinali User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Code:
<xsl:template match="/inputtable">
<table>
<xsl:for-each select="editbox">
<tr>
<td><xsl:value-of select="name"</td>
<td><input type="text"/></td>
</tr>
</xsl:for-each>
</table>
</xsl:template>

Reply With Quote
  #3  
Old July 28th, 2004, 08:38 AM
cancerian007 cancerian007 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Location: Bangalore, India
Posts: 2 cancerian007 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
How to assign value to a global variable?

hi.. I m trying to convert an XML file to HTML using XSL.
the XML code is :
<SignonRq>
<CustLoginId>
<Title>Login Id</Title>
<Type>Text</Type> -- this should make a textbox in HTML
<Size>16</Size>--max length of the textbox should be 16
</CustLoginId>
<SignOnPswd>---</SignOnPswd>
</SignonRq>

The XSL is:
<xsl:template match="CustLoginId/Type">
<xsl:variable name="type"><xsl:apply-templates/></xsl:variable>
</xsl:template>

<xsl:template match="CustLoginId/Size">
<xsl:variable name="size"><xsl:apply-templates/></xsl:variable>
<input type="{$type}" maxlength="{$size}"/>
</xsl:template>

What i m interested in is the variable " type " value should be inserted in the second template match tag...
If i define a global variable (temp), how do i asssign the value of "type" from the first tag so that i can use the value in the second tag(instead if "{$type}")?
Thanks in advance....
manish.

Reply With Quote
  #4  
Old July 28th, 2004, 11:38 AM
Malinali Malinali is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Location: Buenos Aires, Argentina
Posts: 74 Malinali User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
I think you can't use a variable you declared on one matching template in another matching template (the ones you "call" using apply-templates) because the scope changed. If you're use to OO programming, it's like they're all private. Some parsers won't even let you use one from the templates that are supposed to not to change the scope.

What about this?

Code:
<xsl:template match="CustLoginId">
<input>
<xsl:attribute name="type"><xsl:value-of select="Type"/></xsl:attribute>
<xsl:attribute name="maxlength"><xsl:value-of select="Size"/></xsl:attribute>
</input>
</xsl:template>

Reply With Quote
  #5  
Old July 29th, 2004, 10:33 AM
Malinali Malinali is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Location: Buenos Aires, Argentina
Posts: 74 Malinali User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Sometimes you can "declare" a "global" variable if you do it outside any template, let's say between
Code:
<xsl:stylesheet .....>

and
Code:
<xsl:template match="/">

Reply With Quote
  #6  
Old July 30th, 2004, 01:13 AM
cancerian007 cancerian007 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Location: Bangalore, India
Posts: 2 cancerian007 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Thanks....

hey.. thanks for the tip man... that has helped me a lot n i was able to generate the complete HTML page as required. Thanks again.
But again there is a small problem. I need to make the XSL code generalised. I mean to say.. the same XSL file should work fine with other XML file and provide me the desired HTML.
XML code :<CustLoginId>

<Title>Login Id.</Title>

<Type>Text</Type>

<Size>16</Size>

</CustLoginId>

XSL code:<TR>
<TD>
<xsl:value-of select="SignonRq/CustLoginId/Title"/></TD>
<TD><input>
<xsl:attribute name="name"><xsl:value-of select="SignonRq/CustLoginId/Title"/></xsl:attribute>
<xsl:attribute name="type"><xsl:value-of select="SignonRq/CustLoginId/Type"/></xsl:attribute>
<xsl:attribute name="maxlength"><xsl:value-of select="SignonRq/CustLoginId/Size"/></xsl:attribute>
</input></TD>
</TR>
Like in this case i have given the name of the tag specifically for this XML file only. But can this code be generalised to make this work with other XML files with the same tree structure but different tag names?
Thanks again.

Reply With Quote
  #7  
Old August 3rd, 2004, 12:54 PM
Malinali Malinali is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Location: Buenos Aires, Argentina
Posts: 74 Malinali User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
I've been trying to figure out this one in my spare times, but I can't get it.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreXML Programming > XSL Stylesheet advice


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 | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
Stay green...Green IT