473,703 Members | 2,381 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

XSL: Adding namespace prefix to elements read from external file

Hello,

I'm currently using <xsl:copy-of select="documen t(...)/svg:svg"/to
embed an SVG file into an XHTML file. I already defined the SVG
namespace and assigned svg as its prefix in my XSLT 1.0 sheet.

What commands instead of copy-of could I use in order to get the
prefix with every element from the external file, e.g. <svg:svg>,
<svg:lineetc. instead of just <svgand <line>, as it is noted in
the external file?
I tried to create new elements and assign everything, but it didn't
work out so far.
Thank you for any helpful suggestion!

Regards,
Johannes

Feb 11 '07 #1
5 6958
jo************* @gmx.net wrote:
I'm currently using <xsl:copy-of select="documen t(...)/svg:svg"/to
embed an SVG file into an XHTML file. I already defined the SVG
namespace and assigned svg as its prefix in my XSLT 1.0 sheet.

What commands instead of copy-of could I use in order to get the
prefix with every element from the external file, e.g. <svg:svg>,
<svg:lineetc. instead of just <svgand <line>, as it is noted in
the external file?
I tried to create new elements and assign everything, but it didn't
work out so far.
Does the external SVG document define the SVG namespace properly (e.g.
as its default namespace
<svg xmlns="http://www.w3.org/2000/svg">
or with some prefix e.g.
<svg:svg xmlns:svg="http ://www.w3.org/2000/svg">
)? Then xsl:copy-of should suffice to create elements in the SVG
namespace in the result tree. The prefix finally used for serialization
should not matter.
Or why are you interested in the prefix?

--

Martin Honnen
http://JavaScript.FAQTs.com/
Feb 11 '07 #2
What commands instead of copy-of could I use in order to get the
prefix with every element from the external file, e.g. <svg:svg>,
<svg:lineetc. instead of just <svgand <line>, as it is noted in
the external file?
Assuming that everything is working properly (which it may not be, but
you haven't shown us an example)... What may be happening is that your
system's serializer has chosen to make the SVG namespace the default
namespace; once that's been done, the prefix does not have to appear on
every element (but all contained elements which are *NOT* in that
namespace must either have a prefix or a new default namespace
declaration to break that association).

The above also assumes you're going through a standard serializer. If
you're taking the XSLT processor's output directly as SAX or DOM, the
prefixes may not be present, since they're considered "syntactic sugar";
you should be operating entirely off the localname and namespace URI, or
explicitly running the output document through a normalization stage if
you need the prefixes (which, as I said, is normally done in the
serializer if you're outputting XML markup).

If you want more specific advice, you'll have to be more specific about
what you're doing and what you're seeing. A small (ten-line or so)
example can be useful as a way of explaining that.
--
() ASCII Ribbon Campaign | Joe Kesselman
/\ Stamp out HTML e-mail! | System architexture and kinetic poetry
Feb 11 '07 #3
Hello,

thanks for your replies. To illustrate what is going on, I made some
excerpts from my XSLT stylesheet and pasted them at the end.
The SVG files to be inserted start with <svg xmlns:"http://www.w3.org/
2000/svg" ... >, i.e. they have the correct namespace URI but no
prefix assigned.

As I need the output code for some kind of demonstration, I'd rather
include the prefixes with the SVG section.

Regarding your answer, Joe, I didn't entirely get what you said in the
2nd paragraph. I'm just feeding my files into Instant Saxon and have a
look at its output.
Regards,
Johannes
XSLT file header and root:

<?xml version="1.0" encoding="utf-8"?>
<xsl:transfor m xmlns="http://www.w3.org/1999/xhtml" xmlns:xsl="http ://
www.w3.org/1999/XSL/Transform"
xmlns:math="htt p://www.w3.org/1998/Math/MathML" xmlns:svg="http ://
www.w3.org/2000/svg" version="1.0">

When a reference to a SVG file is found, a template is called to
process it:

<xsl:call-template name="getFigure ">
<xsl:with-param name="svgfile"> <xsl:value-of select="@src"/></
xsl:with-param>
</xsl:call-template>

<xsl:template name="getFigure ">
<xsl:param name="svgfile"/>
<xsl:copy-of select="documen t($svgfile)/svg:svg"/>
</xsl:template>

Feb 11 '07 #4
jo************* @gmx.net wrote:
The SVG files to be inserted start with <svg xmlns:"http://www.w3.org/
2000/svg" ... >, i.e. they have the correct namespace URI but no
prefix assigned.
Which is fine; you're using the default namespace.
As I need the output code for some kind of demonstration, I'd rather
include the prefixes with the SVG section.
Unfortunately, while there's an official mechanism in XSLT 1.0 for
hinting that a prefix may not be needed, there isn't a clear one for
hinting that you _do_ want it used preferentially.

I guess you could try forcing an explicit declaration of the svg: prefix
into your output document, and see if that's enough of a hint for your
processor to realize that you want it to use this prefix rather than a
default binding... something like:
<xsl:template name="getFigure ">
<xsl:param name="svgfile"/>
<svg:svg xmlns:svg="http ://www.w3.org/2000/svg">
<xsl:copy-of select="documen t($svgfile)/svg:svg/(@*|node())"/>
</svg:svg>
</xsl:template>
If you really need a reliable portable solution... ugh. Best I can think
of is to recreate copy-of via recursion, and set up a template which
matches elements in the svg namespace and explicitly reconstructs them
using xsl:element with prefix="svg"... And even that may not be
guaranteed, depending on how the document is processed after it leaves
the XSLT engine.

--
() ASCII Ribbon Campaign | Joe Kesselman
/\ Stamp out HTML e-mail! | System architexture and kinetic poetry
Feb 11 '07 #5
On 11 Feb., 19:26, Joe Kesselman <keshlam-nos...@comcast. netwrote:
I guess you could try forcing an explicit declaration of the svg: prefix
into your output document, and see if that's enough of a hint for your
processor to realize that you want it to use this prefix rather than a
default binding... something like:
<xsl:template name="getFigure ">
<xsl:param name="svgfile"/>

<svg:svg xmlns:svg="http ://www.w3.org/2000/svg">
<xsl:copy-of select="documen t($svgfile)/svg:svg/(@*|node())"/>
</svg:svg>
</xsl:template>
That didn't work I'm afraid. After all, the processor is obviously
aware of the namespace prefix (at least for the elements within the
stylesheet). It was mandatory to write document($svgfi le)/svg:svg,
whereas document($svgfi le)/svg wouldn't work. I'll give the creation
of new elements another try and will drop a note when it works out.
Regards,
Johannes

Feb 11 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
2270
by: chris | last post by:
Hi, After going back through the XSL tutorials and the help here I have largely solved the problem of merging two XHTML files, but one small detail remains... The parser outputs <html xmlns="http://www.w3.org/1999/xhtml" xmlns:xhtml="http://www.w3.org/1999/xhtml">
4
2435
by: Kevin Dean | last post by:
I'm trying to create an XSL transformation that will strip out development-specific attributes from deployment descriptors and other XML files. I have already successfully done so with web.xml but I'm at a complete loss as to what is wrong with the one below. This is a very abbreviated server-config.wsdd: <?xml version="1.0" encoding="UTF-8"?> <deployment xmlns="http://xml.apache.org/axis/wsdd/"...
2
2736
by: Ravi | last post by:
My XML looks like: <abc> <def type="apple"> 1 </def> <def type="peach"> 2 </def> <def type="orange"> 3 </def> <def type="banana"> 4 </def> <def type="plum"> 5 </def> </abc>
1
2698
by: Ken Larson | last post by:
I have a question about using XSL to extract information from an SVG (XML) file that has a DOCTYPE/DTD declaration. I am able to do this successfully if I write my own SVG files without such a declaration. However, I would like to extract some parts of an SVG file exported by illustrator. When I try this, my XSL file is no longer able to access the nodes in the SVG document properly - somehow related to the DOCTYPE/DTD declaration. ...
2
7410
by: David Nedrow | last post by:
OK, I have a problem which I'm guessing is simply my inability to figure out a select pattern in XSL. I have an XML file similar to the following: <?xml version="1.0"?> <?xml-stylesheet type="text/xsl" href="vmv.xsl"?> <ruleset xmlns="https://foo.com"
3
4954
by: Jacques | last post by:
I'm experiencing the following problem The source xml file uses a prefix (wpl:) and look like this (shortened): ----------------------------------------------------------------- <?xml version="1.0" encoding="UTF-8"?> <wpl:Destinations xmlns:wpl="www.sapportals.com/portal/landscape" xmlns:xsi="http://www.w3.org/2000/10/XMLSchema-instance" xsi:schemaLocation="wpl_jco_destionations_v10.xsd"> <wpl:Destination...
1
1896
by: Lothar Lemnitzer | last post by:
Dear fellows, I have a problem with matching namespaces in an XML document and an XSLT stylesheet (at least I think that this is the source of trouble). My XML document looks like this: 1 <?xml version="1.0" encoding="ISO-8859-1" standalone="no"?> 2 <!DOCTYPE relations SYSTEM "germanet_relations.dtd"> 3 <relations>
1
5402
by: jorgen.wahlund | last post by:
Hi I have problems with transforming a xml document with Xalan and javax.xml.Transformer. Following xsl is used: <xsl:stylesheet version='1.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform' xmlns:xalan="http://xml.apache.org/xslt" xmlns:java="java"
5
8917
by: Greg Collins [MVP] | last post by:
I have an ASP.NET page that uses a tag: <asp:Xml id="foo" runat="server" DocumentSource="rss.xml" TransformSource="rss20.xsl" /> This creates a Web page from an XML file that was generated by InfoPath. By default InfoPath inline's their images in base64 encoding. These need to be extracted out to be displayed. I've got my XSL set up to be able to pull out images and manage them separately. According to Microsoft, they need to be decoded...
0
8662
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9244
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9004
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6585
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5922
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4421
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3114
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2439
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2058
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.