Subject: Re: Subtype/inheritance in XML, how does XSLT handle it?
From: "Agnisys Technology \(P\) Ltd." <agnisys@xxxxxxxxx>
Date: Wed, 31 Aug 2005 07:54:04 -0700 (PDT)
|
Thank you Jay and everyone else who responded. This is a good start for me. In fact last couple of
days I've been trying to use this solution.
Anupam.
--- Jay Bryant <jay@xxxxxxxxxxxx> wrote:
> Welcome to the list.
>
> I've been on the list long enough to tell you that this topic is not that
> common (but not unknown, either). We tend to get grumpy when the same
> question gets asked three times in two days (as happened over the last two
> days), but this one hasn't turned up in a while.
>
> You're basically up against a form of cross-referencing, which XSLT does
> well.
>
> To handle it, you set up a template to match A and a template that handles
> enough of B to ensure that A gets handled. Then you write the A template to
> process the parts of the A_DEC node that you want. Here's how:
>
> <?xml version="1.0" encoding="UTF-8"?>
> <xsl:stylesheet version="1.0"
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
>
> <xsl:template match="A">
> <xsl:variable name="thisname" select="@name"/>
> <xsl:variable name="thisref" select="@ref"/>
> A.doc = <xsl:value-of select="doc"/>
> A.v1 = <xsl:value-of select="//*[local-name() = $thisref][@name =
> $thisname]/v1"/>
> </xsl:template>
>
> <xsl:template match="A_DEC"/>
>
> <xsl:template match="B">
> <xsl:apply-templates select="A"/>
> </xsl:template>
>
> </xsl:stylesheet>
>
> I tested that with Saxon 8 and got the results you wanted.
>
> If you can, avoid using the // path option. It's the most expensive thing
> you can do. Still, this kind of searching can be one of the times that // is
> the way to go.
>
> Let us know what other issues we can address. You'll find the list pretty
> helpful, provided you take the time to ask good questions, as you did here.
>
> Happy XSLTing.
>
> Jay Bryant
> Bryant Communication Services
>
> ----- Original Message -----
> From: "Agnisys Technology (P) Ltd." <agnisys@xxxxxxxxx>
> To: <xsl-list@xxxxxxxxxxxxxxxxxxxxxx>
> Sent: Friday, August 26, 2005 10:43 PM
> Subject: Subtype/inheritance in XML, how does XSLT handle it?
>
>
> > Hi,
> > Can XSL handle subtypes/inheritance in XML?
> >
> > I have an XML document that "declares" a type "someA" and then uses it, as
> follows:
> > <top>
> > <A_DEC name="someA">
> > <doc> aaaaaaa </doc>
> > <v1> 100 </v1>
> > </A_DEC>
> >
> > <B>
> > <A ref="A_DEC" name="someA">
> > <doc> bbb </doc>
> > </A>
> > </B>
> > </top>
> > ---------------------
> > I want this to be transformed into :
> > A.doc = bbb
> > A.v1 = 100
> > ---------------------
> > Note that doc value is overridden from the XML doc and the v1 value is
> used from the original
> > definition.
> >
> > How do I make XSLT use the entity "A_DEC" when it encounters A?
> >
> > I'm designing the XML language, so I have the flexibility. If this kind of
> problem is solved
> > differently in XML, please advice.
> >
> > I would much appreciate even partial answers or any pointers.
> > Thanks,
> > Anupam.
> >
> > P.S. I'm new to XML, and to this list, please excuse if this question has
> been answered before.
> > Unfortunately I couldn't find the answer when I searched.
> >
> >
> >
> >
> >
> > ____________________________________________________
> > Start your day with Yahoo! - make it your home page
> > http://www.yahoo.com/r/hs
>
>
____________________________________________________
Start your day with Yahoo! - make it your home page
http://www.yahoo.com/r/hs
|