xsl-list
[Top] [All Lists]

RE: [xsl] adding namespace node to arbitrary <xsl:element> - xslt 1 or 2

2007-05-16 16:25:42
You don't need to add a namespace node to the element in the result tree, it
already has one.

What you are trying to do is to force the serializer to output a redundant
namespace declaration, and that can't be done. Serializers go to great
lengths to minimize the number of namespace declarations that are output: if
a declaration was output for every namespace node, the output would be
hopelessly cluttered.

There's something wrong with the downstream process if it requires the
namespace declaration to be on the <dc:title> element rather than on some
outer element in the same document. Ideally you should correct the
downstream process.

But in this case you could solve the problem by ensuring that ancestors of
the <dc:title> do *not* have a namespace node for the dc namespace. You
haven't shown enough code for us to see why they currently have that
namespace.

Michael Kay
http://www.saxonica.com/ 

-----Original Message-----
From: Benjamin Li [mailto:xycodex(_at_)gmail(_dot_)com] 
Sent: 16 May 2007 22:47
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] adding namespace node to arbitrary 
<xsl:element> - xslt 1 or 2

Hi,

I'm having a problem dealing with namespaces in my stylesheet.

My problem is that I have to transform a document into a 
result document that contains inline xml. let me explain.

The result document is read by another java program (created 
by an external party), and a certain section/fragment of the 
result document is read as an independent xml file, hence the 
term 'inline'.

The main problem is that I need to re-declare certain 
namespaces in this fragment. I managed to get to this stage:


<mets:mets xmlns:dc=3D"http://purl.org/dc/elements/1.1/";
          xmlns:xs=3D"http://www.w3.org/2001/XMLSchema";
          xmlns:xsi=3D"http://www.w3.org/2001/XMLSchema-instance";
          xmlns:xlink=3D"http://www.w3.org/1999/xlink";
          xmlns:mets=3D"http://www.loc.gov/METS/";
          OBJID=3D"test:chc03560000270001001"
          LABEL=3D"Ram=F3n"
          TYPE=3D"FedoraObject">
  <mets:metsHdr RECORDSTATUS=3D"A"/>
  <mets:dmdSecFedora STATUS=3D"A" ID=3D"DC">
     <mets:descMD ID=3D"DC1.0">
        <mets:mdWrap MIMETYPE=3D"text/xml" MDTYPE=3D"DC" LABEL=3D"DC">
           <mets:xmlData>
<!--start inline xml-->
              <oai_dc:dc xmlns:oai_dc=3D"
http://www.openarchives.org/OAI/2.0/oai_dc/";>
                 <dc:title>Some Title</dc:title>
                 <dc:creator>Barqu=EDn, B.J.</dc:creator>
                 <dc:format>image/tiff</dc:format>
                 <dc:type>Still Image</dc:type>
              </oai_dc:dc>
<!--end inline xml-->
           </mets:xmlData>
        </mets:mdWrap>
     </mets:descMD>

ie, in this example, the fragment with the element <oai_dc> 
is read independently as its own xml document. thus, the java 
program chokes up whe= n it tries to read the <dc:title> and 
other child elements, since dc is not defined in the <oai_dc> 
scope in that fragment, as far as the program is concerned.

it seems that when the xslt processor serializes the output 
document, it does some 'fixup' with regards to namespaces.
i tried using xsl:copy to copy the dc namespace node, but it 
doesnt add the declaration on the element, i think it got 
removed when the result tree was serialized (is there an xslt 
debugger where i can see the result tree while it is being 
built??) i managed to get the the oai_dc namespace declared 
in the element, presumably because it was not already 
declared in the document element of the source document, 
which is the case for the dc namespace. here's the
template:

   <xsl:template match=3D"mets:xmlData">
       <xsl:element name=3D"mets:xmlData">
           <xsl:element name=3D"oai_dc:dc" namespace=3D"
http://www.openarchives.org/OAI/2.0/oai_dc/";>
               <xsl:copy-of select=3D"/mets:mets/namespace::dc" />
               <xsl:copy-of select=3D"node()" />
           </xsl:element>
       </xsl:element>
   </xsl:template>

from what i can see, this whole 'inline xml' business is a 
Bad Idea, but i have little choice, so any help is appreciated!

cheers,
ben

--~------------------------------------------------------------------
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>