Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > XSL transform trying to be smarter?

Reply
Thread Tools

XSL transform trying to be smarter?

 
 
Wizfrog
Guest
Posts: n/a
 
      07-24-2007
Hello,

I am using XSL to transform a XML file into a HTML output.
classic

so, I have a tag calling an image with a local path as

<img src="images/myimage.jpg"/>

nothing really strange here...

I am just surprised to see that the output includes the FULL path to
the image.
so, XSL first is able to figure out that my img tag is an html tag and
put in the full path there.

it makes for a HUGE src field, and since I am generating an output
with several images for each field, and hundreds of fields, it's just
slow.
i am thinking that all this extra text in the HTML just makes it
heavier to handle, and just wish to use the simpler local path.

Why is XSL generating the full path like this? How do I get around
this?



other thing i found out is that it keeps inserting attributes like:

xmlns:td="urn:schemas-microsoft-com:datatypes" all over the place in
my <div>

I tried to use <xsl:element name="div"> instead of just <div> but it
didn't help.

any idea?

thanks for help!

 
Reply With Quote
 
 
 
 
Joe Kesselman
Guest
Posts: n/a
 
      07-24-2007
Wizfrog wrote:
> I am just surprised to see that the output includes the FULL path to
> the image.
> so, XSL first is able to figure out that my img tag is an html tag and
> put in the full path there.


What are you viewing the output with? XSLT *shouldn't* be expanding
relative paths to full paths. Of course other tools (such as the
browser) may be doing so.

> Why is XSL generating the full path like this? How do I get around
> this?


If you're sure it's happening in the XSLT processor, I think that
processor's broken. Try another?


> other thing i found out is that it keeps inserting attributes like:
> xmlns:td="urn:schemas-microsoft-com:datatypes" all over the place in
> my <div>


XSLT will insert the appropriate namespace nodes whenever it copies an
element from a namespaced context. Some XSLT processors are better than
others at recognizing that a namespace declaration is already in scope
and that new declarations don't have to be issued. You may be able to
help the processor/serializer by making sure a declaration for this
prefix appears near the root of the document, so it *is* already in scope.

--
() ASCII Ribbon Campaign | Joe Kesselman
/\ Stamp out HTML e-mail! | System architexture and kinetic poetry
 
Reply With Quote
 
 
 
 
Wizfrog
Guest
Posts: n/a
 
      07-24-2007
I'm printing the output in the browser into a TEXTAREA container. Note
that I'm using local file here.

I was doing this because as I dump the output in a div, the divs next
to it get moved around, which does not happen if I just dump text. I
thought the xsl output may be malformed, but it's fine, except for all
the added junk.



I'm not sure I am familiar enough with the namespace stuff.
what is xmlns:dt about? it shows up in the IMG tag

my 1st tag is already:
<xsl:stylesheet version="1.0" xmlnssl="http://www.w3.org/1999/XSL/
Transform" xmlns:dt="urn:schemas-microsoft-com:datatypes">

so why would it need to show up again? should I try version="2.0" ?


 
Reply With Quote
 
Joe Kesselman
Guest
Posts: n/a
 
      07-24-2007
Joe Kesselman wrote:
>> other thing i found out is that it keeps inserting attributes like:
>> xmlns:td="urn:schemas-microsoft-com:datatypes" all over the place in
>> my <div>


I forgot to add that you may also want to play with the
exclude-result-prefixes directive, if you're sure the prefix is not
being used in your output tree (including in text content such as
XPaths). See discussion at

http://www.w3.org/TR/xslt#literal-result-element

--
() ASCII Ribbon Campaign | Joe Kesselman
/\ Stamp out HTML e-mail! | System architexture and kinetic poetry
 
Reply With Quote
 
Joe Kesselman
Guest
Posts: n/a
 
      07-24-2007
Wizfrog wrote:
> I'm not sure I am familiar enough with the namespace stuff.
> what is xmlns:dt about?


It binds the dt prefix to a particular namespace name.

> <xsl:stylesheet version="1.0" xmlnssl="http://www.w3.org/1999/XSL/
> Transform" xmlns:dt="urn:schemas-microsoft-com:datatypes">


Which means this namespace is in scope for your entire stylesheet, so
any element in the stylesheet inherits this declaration, so when you
copy them to the result document the declaration comes with them.

You can try outputting it earlier in your *RESULT* document and hope
that inheritance keeps it from being repeated all over the place. Or, if
you aren't using it, you can remove that declaration from the stylesheet
and/or move it down to the place(s) where it is actually being used.

> should I try version="2.0" ?


2.0 doesn't change the behavior I cited. Either don't declare namespaces
you aren't using, or try to make sure the output document declares them
high up and hope your serializer's smart enough to take advantage of
that, or explicitly suppress them (which works only if they aren't being
referenced, and may cause trouble if there really was something that
needed them -- basically, understand what you're doing before pulling
the trigger), or live with the fact that XSLT will declare them when it
notices that you haven't yet done so and they might be needed.
(Redundant or distributed declarations are verbose but otherwise harmless.)




>
>



--
() ASCII Ribbon Campaign | Joe Kesselman
/\ Stamp out HTML e-mail! | System architexture and kinetic poetry
 
Reply With Quote
 
Wizfrog
Guest
Posts: n/a
 
      07-24-2007
got it. thanks

what is dt for anyway? (I assume datatype) but what does it mean?

I guess I used the header from somewhere else and didn't realize this
was there.

when should i have to use the dt namespace?

 
Reply With Quote
 
Joe Kesselman
Guest
Posts: n/a
 
      07-24-2007
Wizfrog wrote:
> what is dt for anyway? (I assume datatype) but what does it mean?


To find out what a namespace is used for, try to find out who defined
the URI that represents it its name. (The prefix being bound is just a
convenience, and is not itself meaningful; you can use any prefix as
long as you're consistant about it.)

Obviously, this one's defined by Microsoft. Websearch tells us that "The
urn:schemas-microsoft-com:datatypes namespace defines a field used when
defining properties for the Exchange store schema." If you aren't
working with Exchange documents, you presumably don't need to declare it.

Hence, the simplest way to fix your problem is probably to get rid of
that namespace declaration.


--
() ASCII Ribbon Campaign | Joe Kesselman
/\ Stamp out HTML e-mail! | System architexture and kinetic poetry
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
XSL Question tp xsl:for-each and xsl:variable schaf@2wire.ch XML 1 05-27-2005 09:25 PM
Problems trying to XSL transform a document with entities. annoyed tuna XML 3 04-20-2005 10:03 PM
blocking I/O with javax.xml.parsers.DocumentBuilder.parse() and javax.xml.transform.Transformer.transform() jazzdman@gmail.com Java 1 03-27-2005 06:56 AM
Re: How do i transform an xml with 2 xsl files? Cowboy \(Gregory A. Beamer\) ASP .Net 1 07-03-2003 02:35 PM
What parses the xml/xsl transform in asp.net? System.xml NOT msxml? KathyB ASP .Net 0 06-25-2003 05:03 PM



Advertisments