xsl-list
[Top] [All Lists]

RE: What is wrong with this xsl ?

2003-01-21 01:00:43
You need to declare the namespace for the SurveyML in the xslt file this 
example should give you some idea.

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; 
xmlns:srv="http://mmmm.mmm.edu/SurveyML";>
        <xsl:output method="xml" version="4.0" encoding="UTF-8" indent="yes"/>
        <xsl:template match="/">
                <xsl:apply-templates/>
        </xsl:template>
        <xsl:template match="srv:survey">
                <xsl:element name="survey" 
namespace="http://mmmm.mmm.edu/SurveyML";>
                        <xsl:copy-of select="@id"/>
                        <xsl:copy-of select="srv:surveyInfo"/>
                        <xsl:copy-of select="srv:intro"/>
                        <xsl:apply-templates select="srv:section"/>
                </xsl:element>
        </xsl:template>
        <xsl:template match="srv:section">
                <xsl:variable name="file" select="@id"/>
                <xsl:element name="section" 
namespace="http://mmmm.mmm.edu/SurveyML";>
                        <xsl:attribute name="href"><xsl:value-of 
select="$file"/></xsl:attribute>
                </xsl:element>
        </xsl:template>
</xsl:stylesheet>

If your input data is like this.

<?xml version="1.0"?>
<survey xmlns="http://mmmm.mmm.edu/SurveyML"; id="test" version="2003-alpha" 
UMI="" notes="This is only a demo version of the survey!">
        <surveyInfo/>
        <intro>This survey is just a demo.</intro>
        <section id="section1">
                .....
        </section>
        <section id="section2">
                .....
        </section>
</survey>

Your output will apear as bellow.

<?xml version="1.0"?>
<survey id="test" xmlns="http://mmmm.mmm.edu/SurveyML";>
        <surveyInfo/>
        <intro>This survey is just a demo.</intro>
        <section href="section1"/>
        <section href="section2"/>
</survey>

Edward Middleton

-----Original Message-----
From: Latha V. M. [mailto:latha_vm(_at_)yahoo(_dot_)com]
Sent: Tuesday, January 21, 2003 12:31 PM
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: RE: [xsl] What is wrong with this xsl ?


The xml looks like this:
<?xml version="1.0"?>
<survey xmlns="http://mmmm.mmm.edu/SurveyML";
                        xmlns:xhtml="http://www.w3.org/1999/xhtml";
                
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
                        xsi:schemaLocation="http://cs.wmich.edu/SurveyML 
                                                                                
../XMLSchema/SurveyML/SurveyML.xsd"
                        id="test"
                        version="2003-alpha" 
                        UMI=""
                        notes="This is only a demo version of the survey!"

        <surveyInfo>
        </surveyInfo>
        <intro>
                                        This survey is just a demo.
        </intro>
        <section id="testSection">
                <header>
                        <title>Test section for new SurveyML</title>
                        <subtitle>Test section for the new SurveyML based
on XMLSchema</subtitle>
                        <intro>
                                Hello world!
                        </intro>
                </header>
                <question id="demo_1">
                        <stem>
                                Who are you?
                        </stem>
                        <identity id="identityDemo_1" mandatory="true" />
                </question>
        </section>
</survey>

--- Edward(_dot_)Middleton(_at_)nikonoa(_dot_)net wrote:
Please explain what your desired output is.  It is
not clear from you xslt file.  I think you might be
confusing the match and name in the xsl:template and
not understanding namespaces.   You have defined the
xsl as the namespace for the xsl language 

xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; 

Unless you source document is in xsl (it isn't) you
should not place this namespace marker before
elements that you wish to match that are not xsl.

match = "xsl:survey"

The only template you have supplied that can match
the survey element is

<xsl:template match="*"/>

which will just remove it as you have seen.

match = "/xsl:survey/xsl:section"
match = "xsl:survey"

won't.

Edward Middleton

-----Original Message-----
From: Latha V. M. [mailto:latha_vm(_at_)yahoo(_dot_)com]
Sent: Tuesday, January 21, 2003 11:37 AM
To: XSL-List(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] What is wrong with this xsl ?


Hi,
I have the following xsl code:
<?xml version="1.0" encoding="UTF-8"?>

[lsunkara(_at_)ateserver ateserver2003]$ cat
XSLSource/SectionForm/split.xsl 
<xsl:stylesheet version="1.1"
       
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
       

xmlns:xhtml="http://www.w3.org/1999/TR/xhtml1/strict";>
<xsl:output method="xml" version="4.0"
encoding="UTF-8" indent="yes"/>

<xsl:template match = "/" >
        <xsl:apply-templates select = "survey" />
</xsl:template>

<xsl:template name="survey" match = "xsl:survey" >
        <survey>
                <xsl:copy-of select =
"/survey/surveyInfo"/>
                <xsl:call-template name =
"section"/>
        </survey>
</xsl:template>

<xsl:template match = "/xsl:survey/xsl:section" name
=
"section" >
        <xsl:variable name = "file" select = "@id"
/>
        <section sname = "{$file}" number =
"{position()}" href = "{$file}" />
        <xsl:document href = "{$file}" >
                <xsl:copy-of select =
"/survey/section" />
        </xsl:document>
</xsl:template>

<xsl:template match = "*" >
</xsl:template>

</xsl:stylesheet> 
When I run this code as under it does not execute
the
template for survey, it only executes the "/"
template.
#!/usr/bin/ksh
#This script uses the Xalan tool to translate a
survey
section

#----------------------------------------------------------------------------------------

#LOCALCLASSPATH=/home/lsunkara/xmlold/xalan-j_1_2_2/xalan.jar:/home/lsunkara/xmlold/xalan-j_1_2_2/xerces.jar

LOCALCLASSPATH=/usr/java/xalan-j_2_4_0/bin/xalan.jar:/usr/java/xalan-j_2_4_0/bin/xercesImpl.jar:/usr/java/xalan-j_2_4_0/bin/xml-apis.jar

#----------------------------------------------------------------------------------------
XSL=XSLSource/SectionForm/split.xsl

INPUT=XMLSource/demo-survey.xml
OUTPUT=split1.xml

java -classpath $LOCALCLASSPATH
org.apache.xalan.xslt.Process -IN $INPUT -OUT
$OUTPUT
-XSL $XSL -INDENT 2 -TT 

The xml looks like:
<survey>
<surveyInfo>
</surveyInfo>
<intro>
</intro>
<section id="test">
<question></question>
</section>
</survey>

=====
"Great minds have purposes, others have wishes."

__________________________________________________
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up
now.
http://mailplus.yahoo.com

 XSL-List info and archive: 
http://www.mulberrytech.com/xsl/xsl-list


 XSL-List info and archive: 
http://www.mulberrytech.com/xsl/xsl-list



=====
"Great minds have purposes, others have wishes."

__________________________________________________
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
http://mailplus.yahoo.com

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list



<Prev in Thread] Current Thread [Next in Thread>