This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: getting Not well formed xslt output


Yogesh:

This is a job for the step-wise identity stylesheet. (It appears in the 
XSLT spec, section 7.5.)

<xsl:template match="@*|node()">
   <xsl:copy>
     <xsl:apply-templates select="@*|node()"/>
   </xsl:copy>
</xsl:template>

Basically this traverses the tree one node at a time, copying each node to 
output.

Add to this two templates, one that handles your 'DEST' attribute, and one 
that handles your 'imtask' attribute (since these are the only things in 
your input that are going to change).

<xsl:template match="@DEST">
   <xsl:copy>
     <xsl:value-of select="../@imtask"/>
   </xsl:copy>
</xsl:template>

<xsl:template match="@imtask"/>

The first copies the DEST attribute, except it takes the value of the same 
element's 'imtask' attribute for its value. The second removes the 'imtask' 
attribute. Both of these templates have a higher priority than the generic 
identity template, so will apply where they can.

The technique, or pattern, is very useful for such simple "scrub 
transforms" as yours. I'm sure it's described in the FAQ. Since it's based 
on the identity transform, your problem of knowing how many attributes 
there are, and which, simply goes away.

Good luck,
Wendell

BTW -- how'd this thread get its Subject line? It's basically useless: this 
has nothing to do with well-formedness.

At 04:23 PM 7/10/01, you wrote:
>Hi Mike,
>I have one problem like this:
>my node is like this:
><ACTION TYPE="accept" LABEL="Next" task="go" DEST="#password" >
>
>For SAXparsing in JAVA I make it well-formed like this:
><ACTION TYPE="accept" LABEL="Next" task="go" DEST="#password"
>imtask="20"></ACTION>
>
>On This code if I apply XSLT I want output like this:
><ACTION TYPE="accept" LABEL="Next" task="go" DEST="20" >(20 is value of
>imtask)
>
>Now I am having a problem how will I construct this node with keeping all
>previous attributes as it is and changing value of dest attribute and not
>closing it.If I write a template for this how I will be adding exact no. of
>attributes and not closing it.
>
>Please advice.
>Thanx in advance,
>-Yogesh
>
>
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


======================================================================
Wendell Piez                            mailto:wapiez@mulberrytech.com
Mulberry Technologies, Inc.                http://www.mulberrytech.com
17 West Jefferson Street                    Direct Phone: 301/315-9635
Suite 207                                          Phone: 301/315-9631
Rockville, MD  20850                                 Fax: 301/315-8285
----------------------------------------------------------------------
   Mulberry Technologies: A Consultancy Specializing in SGML and XML
======================================================================


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]