I suspect you will have to fall back on XSLT to do a fixup, could also be done 
quite easily with SAX.

On Tuesday 26 November 2002 09:59 am, Adam Griffiths wrote:
> Hi
> I have another question about namespaces and taglibs. I could work
> around the problems in my last question but this time the namespace
> really matters.
>
> I wish to write a simpletaglib which generates XML in a namespace other
> than it's own. Is this possible? How do I do it?
>
> For example:
>
> <xsp:page>
> <!-- etc -->
> <mytaglib:makexml\>
> <!-- etc -->
> </xsp:page>
> Gives:
>
> <page>
> <!-- etc -->
> <tagetnamespace:fragment>
> <!-- fragment elements -->
> </tagetnamespace:fragment>
> <!-- etc -->
> </page>
>
> I would assume this is a common requirement...
>
> My thanks in advance
>
> Adam
>
>
> -----Original Message-----
> From: Adam Griffiths [mailto:[EMAIL PROTECTED]]
> Sent: 20 November 2002 18:01
> To: [EMAIL PROTECTED]
> Subject: A SimpleTaglib and namespaces.
>
>
> Hi all,
>
> I'm writing a SimpleTaglib and would really appreciate some comments. I
> have included example code below to illustrate what I'm doing. I wish to
> have a tag, <GC:makemaintag/>, expanded into an xml fragment by my
> taglib.
>
> First of all, this is my first taglib (:-), have I got the right idea?
> Could I do it a better way?
>
> Second, I've found that the resulting xml fragment has the xml namespace
> written in every tag, which is rather unnecessary. Is there a way to get
> the namespace declared in the parent tag and not in all of it's
> children?
>
> I can live with all the namespaces but seeing as I'm a bit of a perl
> newbie and a taglib newbie it would be great if you can pass your eyes
> over my code below.
>
> Cheers
>
> Adam
>
>
> The xml fragment I wish to build is:
>
>   <maintag>
>     <item>
>       <title></title>
>       <id></id>
>       <value></value>
>     </item><!-- repeated -->
>     <moreinfo></moreinfo>
>   </maintag>
>
> I am using a sub:
>
>   sub makemaintag: struct{
>     #see below for code
>   }
>
> And this results in this xml being output:
>
>   <GC:maintag xmlns:GC="http://xmlns.domain.co.uk/xsp/GC";>
>     <GC:moreinfo xmlns:GC="http://xmlns.domain.co.uk/xsp/GC";>these items
> were created by an xsp</GC:moreinfo>
>       <GC:item xmlns:GC="http://xmlns.domain.co.uk/xsp/GC";>
>          <GC:title xmlns:GC="http://xmlns.domain.co.uk/xsp/GC";>first
> item</GC:title>
>   <!-- see bellow for complete list -->
>
>
>
> ##############################################
> Source code, in more detail
> ##############################################
> ______________________________________________
> My Test XSP file
> ______________________________________________
>
> <?xml version="1.0"?>
> <?xml-stylesheet href="." type="application/x-xsp"?> <?xml-stylesheet
> href="test.xsl" type="text/xsl"?>
>
> <xsp:page
> xmlns:xsp="http://www.apache.org/1999/XSP/Core";
> xmlns:GC="http://xmlns.domain.co.uk/xsp/GC";
> language="Perl">
>       <body>
>          <GC:makemaintag/>
>       </body>
> </xsp:page>
>
> ______________________________________________
> My Test Taglib
> ______________________________________________
>
> ### new
> # AxKit XSP taglib
> # Adam Griffiths
> # 20/11/2002 - v.0.01
> ###
>
> package AxKit::XSP::GC;
> use Apache::AxKit::Language::XSP::SimpleTaglib;
> use vars qw/@ISA $NS $VERSION/;
>
> @ISA = ('Apache::AxKit::Language::XSP::SimpleTaglib');
>
> # define the namespace we use
> $NS = 'http://xmlns.domain.co.uk/xsp/GC';
>
> $VERSION = '0.01';
>
>
>     package AxKit::XSP::GC::Handlers;
>     use strict;
>
> sub makemaintag: struct{
>         return << 'EOF';
> my $dynamicvalue='on the fly'; #could be the result of some routine or
> another my $item1 = {
>   title=>"first item",
>   id=>'232',
>   value=>'static value'
> };
> my $item2 = {
>   title=>"second item",
>   id=>'232',
>   value=>$dynamicvalue
> };
> my @itemlist;
> push @itemlist, $item1;
> push @itemlist, $item2;
> #could push more items onto @itemlist here
>
> my $children = {
>   item=> \@itemlist, # \@ gives arrayref
>   moreinfo=>'these items were created by an xsp'
> };
> my $maintag = {
>   maintag=>$children
> };
>
> #gives:
> #<maintag>
> #<item>
> #     <title></title>
> #     <id></id>
> #   <value></value>
> #</item>
> #<moreinfo></moreinfo>
> #</maintag>
>
> $maintag;
> EOF
> }
> 1;
> ______________________________________________
> Resulting XML (you may wish to turn line wraping off!)
> ______________________________________________
>
> <GC:maintag xmlns:GC="http://xmlns.domain.co.uk/xsp/GC";>
>       <GC:moreinfo xmlns:GC="http://xmlns.domain.co.uk/xsp/GC";>these
> items were created by an xsp</GC:moreinfo>
>       <GC:item xmlns:GC="http://xmlns.domain.co.uk/xsp/GC";>
>               <GC:title
> xmlns:GC="http://xmlns.domain.co.uk/xsp/GC";>first item</GC:title>
>               <GC:id
> xmlns:GC="http://xmlns.domain.co.uk/xsp/GC";>232</GC:id>
>               <GC:value
> xmlns:GC="http://xmlns.domain.co.uk/xsp/GC";>static value</GC:value>
>       </GC:item>
>       <GC:item xmlns:GC="http://xmlns.domain.co.uk/xsp/GC";>
>               <GC:title
> xmlns:GC="http://xmlns.domain.co.uk/xsp/GC";>second item</GC:title>
>               <GC:id
> xmlns:GC="http://xmlns.domain.co.uk/xsp/GC";>232</GC:id>
>               <GC:value xmlns:GC="http://xmlns.domain.co.uk/xsp/GC";>on
> the fly</GC:value>
>       </GC:item>
> </GC:maintag>
>
> ______________________________________________
> My prefered resulting XML, can it be done?
> ______________________________________________
>
> <GC:maintag xmlns:GC="http://xmlns.domain.co.uk/xsp/GC";>
>       <GC:moreinfo>these items were created by an xsp</GC:moreinfo>
>       <GC:item >
>               <GC:title >first item</GC:title>
>               <GC:id>232</GC:id>
>               <GC:value >static value</GC:value>
>       </GC:item>
>       <GC:item>
>               <GC:title>second item</GC:title>
>               <GC:id>232</GC:id>
>               <GC:value>on the fly</GC:value>
>       </GC:item>
> </GC:maintag>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]

-- 
Tod Harter
Giant Electronic Brain

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to