Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 25th, 2005, 10:43 AM
Registered User
 
Join Date: May 2005
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default Strange XSLT problem...

I've a weird problem with a XSLT file...

my XSLT translates a XML file into a HTML form and, to solve some problems, I found a solution: to give to each "input" tag a name that is a concatenation of the xml tags to reach that element (much like an xpath)

I managed to obtain this using param and variable...

I'm applying that transformation with a small java program and if I run it from the console... it works. The resulting form is ok and the "input" tag names are "correct" (like: "book:chapter:para:")

But when I run it from a servlet of my webapp, it runs... but the tag names of the resulting forms are not correct, but they miss all the "path" part, so they are like: "para:"

Anybody can help me? I've tryed a lot of alternatives, but they didn't work... :_(



 
Old May 25th, 2005, 10:58 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Debugging other people's code is made considerably easier if they show you the code.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old May 25th, 2005, 11:12 AM
Registered User
 
Join Date: May 2005
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

ok :) thank you!

here the xslt:
Code:
<?xml version="1.0" encoding="utf-8" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <xsl:output method="html" />

    <xsl:template match="/">
        <xsl:apply-templates select="/xsd:schema/xsd:element" />
    </xsl:template>

    <xsl:template match="xsd:element" name="elemento">
        <xsl:param name="predec" select="" />
        <xsl:value-of select="@name" /><br/>
        <input name="{$predec}" type="text"  class="fieldNormal" onBlur="fValid(this, 'string', this.value, 0, 0);"  onFocus="fFocus(this);"/><xsl:value-of select="@type" /><br/>
    </xsl:template>

    <xsl:template match="xsd:complexType/xsd:sequence">
        <xsl:param name="predec" select="" />
        <xsl:apply-templates>
            <xsl:with-param name="predec" select="concat($predec,@name,':')" />
        </xsl:apply-templates>
    </xsl:template>

    <xsl:template match="xsd:element">
        <xsl:param name="predec" select="" />
        <xsl:choose>
            <xsl:when test="contains(@type, ':')">
                <xsl:choose>
                    <xsl:when test="boolean(@maxOccurs)">
                        <div id="{@name}" class="blockstyle">    
                            <xsl:call-template name="elemento">
                                <xsl:with-param name="predec" select="concat($predec,@name,':')" />
                            </xsl:call-template>
                        <input value="-" type="image" src="images/dels.gif" style="vertical-align:middle;" class="delButt" onclick="cutFields(this);" />
                        </div>
                        <span id="w{@name}">
                            <img name="+" src="images/adds.gif" style="vertical-align:middle;" onClick="moreFields('{@name}');" /><span class="recNameBut">[<xsl:value-of select="@name"/>]</span>
                        </span>
                        <br />
                    </xsl:when>
                    <xsl:otherwise>
                        <xsl:call-template name="elemento">
                            <xsl:with-param name="predec" select="concat($predec,@name,':')" />
                        </xsl:call-template>
                    </xsl:otherwise>
                </xsl:choose>                
            </xsl:when>
            <xsl:otherwise>
            <fieldset class="field">
                <legend class="recName"><xsl:value-of select="@name"/></legend>
                <xsl:choose>
                    <xsl:when test="boolean(@maxOccurs)">
                        <div id="{@name}" class="blockstyle">    
                    <xsl:variable name="myType" select="@type" />
                    <xsl:apply-templates select="/xsd:schema/xsd:complexType[@name=$myType]">
                        <xsl:with-param name="predec" select="concat($predec,@name,':')" />
                    </xsl:apply-templates><br/>
                        <input value="-" type="image" src="images/dels.gif" style="vertical-align:middle;" class="delButt" onclick="cutFields(this);" />
                        </div>
                        <span id="w{@name}">
                            <img name="+" src="images/adds.gif" style="vertical-align:middle;" onClick="moreFields('{@name}');" /><span class="recNameBut">[<xsl:value-of select="@name"/>]</span>
                        </span>
                        <br />
                    </xsl:when>
                    <xsl:otherwise>
                <xsl:variable name="myType" select="@type" />
                    <xsl:apply-templates select="/xsd:schema/xsd:complexType[@name=$myType]">
                        <xsl:with-param name="predec" select="concat($predec,@name,':')" />
                    </xsl:apply-templates>
                    </xsl:otherwise>
                </xsl:choose>    
            </fieldset>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>

</xsl:stylesheet>
 
Old May 25th, 2005, 11:15 AM
Registered User
 
Join Date: May 2005
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

...and this is the source (a XSD file):

Code:
<?xml version="1.0" encoding="UTF-8" ?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <xsd:element name="libro" type="Tlibro"/>
    <xsd:complexType name="Tlibro">
        <xsd:sequence>
            <xsd:element name="fronte" type="Tfronte"/>
            <xsd:element name="corpo" type="Tcorpo"/>
        </xsd:sequence>
    </xsd:complexType>
    <xsd:complexType name="Tfronte">
        <xsd:sequence>
            <xsd:element name="titololibro" type="xsd:string"/>
            <xsd:element name="autore" type="xsd:string"/>
            <xsd:element name="editore" type="xsd:string"/>
        </xsd:sequence>
    </xsd:complexType>
    <xsd:complexType name="Tcorpo">
        <xsd:sequence>
            <xsd:element name="capitolo" type="Tcap" maxOccurs="unbounded" />
        </xsd:sequence>
    </xsd:complexType>
    <xsd:complexType name="Tcap">
        <xsd:sequence>
            <xsd:element name="titolo" type="xsd:string"/>
            <xsd:element name="para" type="Tpara" maxOccurs="unbounded" />
        </xsd:sequence>
    </xsd:complexType>
    <xsd:complexType name="Tpara">
        <xsd:sequence>
            <xsd:element name="p" type="xsd:string" maxOccurs="unbounded" />
        </xsd:sequence>
    </xsd:complexType>
</xsd:schema>
 
Old May 26th, 2005, 04:23 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

I don't know why you're getting different results in the two environments, but two observations:

(a) you have two template rules with match="xsd:element". This is an error. The processor
is allowed to report the error, or it's allowed to use the template that comes last. It's
unwise to rely on this behaviour, I would start by fixing this problem.

(b) you have the line

<xsl:param name="predec" select="" />

The select attribute is required to be an XPath expression, and "" isn't, so this is an error
that every XSLT processor ought to report. If it's getting this wrong, then heaven only knows
what else it is getting wrong. Which XSLT processor are you using? [Subtext: there are better
ones available...]

Michael Kay
http://www.saxonica.com/

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old May 26th, 2005, 06:37 AM
Registered User
 
Join Date: May 2005
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Xalan (last version)

well... ok...

Could you give me a tip to "construct" a form element name attribute, like:

<input name="document:title:para" .../>

Because I need it to solve a problem on field names... I use as names the schema names, but within the schema I can have elements with the same name (like a book "title" and a chapter "title") and I'd like to avoid confusion!

I'm in this need:
I generate a html form from a schema, then I must use that form to add,modify and view records of a simple xml-file (used as database).
Now I've problems with:
1) - schema elements with the same name (like the "title" example above)
2) - populating the form, for the "modify" function... I can overwrite a certain "record", but I'm not able to refill the fields as a real Modify need to do...

For the (1) problem I thought of those Xpath-like naming for the form fields... Can be a nice solution? there are better ones?

For the (2) problem I've thought to put a JSP function called in the value of each field... but it's really complex use it for all the cases...) I can extract a given "record" (xml fragment that can fill a form)... but there are better ways to populate my form?

Thank you in advance for your time!







Similar Threads
Thread Thread Starter Forum Replies Last Post
strange IE problem sully7 BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 3 September 19th, 2008 08:44 AM
Strange problem... F3553 C++ Programming 1 October 25th, 2007 03:56 PM
very strange problem! please help! raybristol ASP.NET 1.0 and 1.1 Basics 8 December 15th, 2005 06:46 AM
Simple XSLT Setup w/Strange Result kwilliams XSLT 5 August 5th, 2005 11:47 AM
Strange Behavior With Anchor in XSLT kwilliams XSLT 6 July 21st, 2005 01:52 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.