xsl-list
[Top] [All Lists]

Re: Stylesheet from a stylesheet

2005-03-13 23:24:30
Thanks for your reply. Thanks for suggesting the way to map
namespaces. It looks good to me. I'll also look at JAXB tools (castor)
if it would help me.

But you have got my requirement slightly wrong. I have to write a XSLT
stylesheet that will be capable of generating XSLT stylesheets.
I don't need to write this stylesheet ..
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
xmlns:fo="http://www.w3.org/1999/XSL/Format"; version="1.0">

<xsl:template match="P">
<fo:root>
    <xsl:apply-templates/>
</fo:root>
 </xsl:template>

This has to be the output of my stylesheet(which I need to write) when
it is given as input the mapping XML file.

But thanks for your help!

Best regards,

On Mon, 14 Mar 2005 09:11:38 +0530, 
omprakash(_dot_)v(_at_)polaris(_dot_)co(_dot_)in
<omprakash(_dot_)v(_at_)polaris(_dot_)co(_dot_)in> wrote:


Hi,
I modified your xml file [1] and [2] to include namespaces like below:

<P>
<a a="1">1</a>
<img b="2">2</img>
</P>

and a second XML file is [2]
<!-- The following FO is only a sample and may not be valid  -->
<fo:root>
<fo:flow>
  <fo:block m="1">1</fo:block>
</f:flow>
<fo:instream-foreign-object n="2">2</fo:instream-foreign-object>
</fo:root>

    See below for a possible solution to your second problem. viz
namespace mapping for a sample case when you are transforming from xhtml to
fo. ( I don't see how this will scale in the real world though).

mapping.xml

<map>
<namespace>
  <src prefix="html">http://www.w3.org/1999/xhtml</src>
  <dest prefix="fo">http://www.w3.org/1999/XSL/Format</dest>
</namespace>
</map>

And below are the templates you need to have to get your desired xml file
[2].

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
xmlns:fo="http://www.w3.org/1999/XSL/Format"; version="1.0">

<xsl:template match="P">
<fo:root>
    <xsl:apply-templates/>
</fo:root>
 </xsl:template>

<xsl:template match="a">
<fo:flow>
<fo:block>
<xsl:value-of select="." />
</fo:block>
</fo:flow>

</xsl:template>

<xsl:template match="img">
<fo:instream-foreign-object>
<xsl:value-of select="." />
</fo:instream-foreign-object>
</xsl:template>

You may want to check out some JAXB tools like 'castor' to see how they
specify the mapping information. Using xpath to specify mapping information
appears to me like it would work only if you know the structure of your xml
files beforehand.

GL,
Omprakash.V

                   Midsummer Sun
                   <midsummer.sun@        To:     
xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
                   gmail.com>             cc:     (bcc: omprakash.v/Polaris)
                                          Subject:     [xsl] Stylesheet from 
a stylesheet
                   03/13/2005
                   11:51 PM
                   Please respond
                   to xsl-list


Friends,
 I have to write a XSLT stylesheet from another XSLT stylesheet(a
kind of tool). This question is in continuation to my earlier question
titled "CDATA help".

I'll try to explain my exact requirements with an example ..

Lets say one XML file is [1]
<P>
<a a="1">1</a>
<img b="2">2</img>
</P>

and a second XML file is [2]
<fo:root>
<fo:flow>
  <fo:block m="1">1</fo:block>
</f:flow>
<fo:table n="2">2</fo:table>
</fo:root>

And, there is a mapping XML file (lets say map.xml) like this -
<schemamap>
<!-- element mapping -->
<map>
  <xpath1>/x/p</xpath1>
  <xpath2>/x/u/w</xpath2>
</map>
<map>
  <xpath1>/x/q</xpath1>
  <xpath2>/x/v</xpath2>
</map>
........
........
<!-- attribute mapping -->
<map>
  <xpath1>/x/p/@a</xpath1>
  <xpath2>/x/u/w/@m</xpath2>
</map>
<map>
  <xpath1>/x/q/@b</xpath1>
  <xpath2>/x/v/@n</xpath2>
</map>
........
........

<!-- (possible) namespace mappings -->
........
........
</schemamap>

The XSLT stylesheet (the tool) will take map.xml file as an input and
generate an XSLT stylesheet as output, that will be able to transform
any XML from format [1] to format [2]  .

For e.g. the tool (a XSLT stylesheet) will generate this output (lets
say file gen.xslt) , when it is given as input the file, map.xml -
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; version
="1.0">
 <xsl:template match="/x/p">
   <x>
     <u>
       <w><xsl:value-of select="." /></w>
     </u>
   </x>
 </xsl:template>
 <xsl:template match="/x/q">
   <x>
     <v>
       <xsl:value-of select="." />
     </v>
   </x>
 </xsl:template>
 <xsl:template match="/x/p/@a">
   <xsl:attribute name="m">
     <xsl:value-of select="." />
   </xsl:attribute>
 </xsl:template>
 ....
 ....
</xsl:stylesheet>

When gen.xslt will be applied to any XML file with format [1] the
output should be an XML file with format [2]. Please note that the
above generated XSLT by the tool would probably produce output -
<x>
 <u>
   <w>1</w>
 </u>
</x>
<x>
 <v>
   <w>2</w>
 </v>
</x>
etc..

But it should actually be -
<x>
 <u>
   <w>1</w>
 </u>
 <v>2</v>
</x>
(i.e. nested tags should be taken care, and also attribute mappings
and possible namespace mappings).

The XML files [1] and [2] are dynamic and what they will contain is
unknown.

It seems that XPath expressions are the best way to specify mapping
information between 2 XML formats.. The mapping file is under my
control, so I am free to design it in a better way.. Any suggestion of
specifying mapping information in any other way is welcome..

Presently my target is to map "elements" and "the attributes". But it
is possible that namespaces from format [1] and format[2] may also
need to be mapped. So I have to cater to mapping namespaces also. I
need suggestions of specifying mapping information for namespaces in
map.xml (I am presently unable to think a suitable way for this).

Hope my requirements are clear..

Based on the help I recieved earlier, I believe the tool(a XSLT
stylesheet) will roughly look like -
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="
http://www.w3.org/1999/XSL/Transform";>

<xsl:output method="xml" indent="yes" />

<xsl:template match="/">
  <xsl:element name="xsl:stylesheet"
namespace="http://www.w3.org/1999/XSL/Transform";>
    <xsl:attribute name="version">1.0</xsl:attribute>
    .....

    .....

    .....
  </xsl:element>
</xsl:template>

</xsl:stylesheet>

At present I am looking for XSLT 1.0 solution. I am open to using
extension functions.

If its not achievable with XSLT 1.0(possibly with extensions), I am
then open to XSLT 2.0 ideas.. But please give XSLT 2.0 ideas also!

Waiting for some ideas..

Best regards,

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: 
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

This e-Mail may contain proprietary and confidential information and is sent 
for the intended recipient(s) only.
If by an addressing or transmission error this mail has been misdirected to 
you, you are requested to delete this mail immediately.
You are also hereby notified that any use, any form of reproduction, 
dissemination, copying, disclosure, modification,
distribution and/or publication of this e-mail message, contents or its 
attachment other than by its intended recipient/s is strictly prohibited.

Visit Us at http://www.polaris.co.in

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: 
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



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