|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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. |
|
#2
|
|||
|
|||
|
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> |
|
#3
|
|||
|
|||
|
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. |
|
#4
|
|||
|
|||
|
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> |
|
#5
|
|||
|
|||
|
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="/"> |
|
#6
|
|||
|
|||
|
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. |
|
#7
|
|||
|
|||
|
I've been trying to figure out this one in my spare times, but I can't get it.
|
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > XML Programming > XSL Stylesheet advice |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|