473,394 Members | 1,694 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

${...} values in attributes of an imported XML in XSL ...

I am a bit puzzled and don't know where to look for.
Here is a stylesheet:

<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE stylesheet [
<!ENTITY foo SYSTEM "foo.xml">
]>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml"
indent="yes">
</xsl:output>

<xsl:template match="/">
<xsl:apply-templates select="node()|@*"/>
</xsl:template>

<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>

<xsl:template match="/foohere">
&foo;
</xsl:template>
</xsl:stylesheet>
Now, everything happens appropriately. The first two template rules do
the identity transformation,
then when "/foohere" is found, the foo.xml is added to the result tree
having resolved the entity. All is well.

But in the result tree, I see that there are some weird things that
happen:
- for the portion that comes from foo.xml all occurrences of "${xyz}"
are replaced by "$".

How can I make it take the foo.xml "verbatim"? I have already tried
<xsl:text disable-output-escaping="yes"&foo; </xsl:text>, but it does
not work.

Thanks for help.

DB

Nov 8 '06 #1
5 1312
- for the portion that comes from foo.xml all occurrences of "${xyz}"
are replaced by "$".
You're inserting the contents of foo.xml into the stylesheet. That means
its contents are going to be interpreted as XSLT. Depending on where
these are occurring, they may be interpreted as Attribute Value Templates.

You may want to copy this using the document() function instead.
--
() ASCII Ribbon Campaign | Joe Kesselman
/\ Stamp out HTML e-mail! | System architexture and kinetic poetry
Nov 8 '06 #2

Joe Kesselman wrote:
- for the portion that comes from foo.xml all occurrences of "${xyz}"
are replaced by "$".

You're inserting the contents of foo.xml into the stylesheet. That means
its contents are going to be interpreted as XSLT. Depending on where
these are occurring, they may be interpreted as Attribute Value Templates.

You may want to copy this using the document() function instead.
That's a great advice, thank you. I did not realize that the entity
resolution occurs *for the XSLT* and hence in effect, the XSLT is
modified. Let me take a look at the document() function and report
back.

Thank you, again.
>

--
() ASCII Ribbon Campaign | Joe Kesselman
/\ Stamp out HTML e-mail! | System architexture and kinetic poetry
Nov 8 '06 #3
Yes, document() function works, thank you.

Can you also tell me how to write out (template rule such that) an xml
element as-is, except that all the attributes should be sorted
lexically?

For the benefit of others:

Here is the working version that deals with use of document:

<?xml version="1.0" encoding="ISO-8859-1"?>

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:param name="foo" select="'foo.html'"/>
<xsl:output method="xml"
indent="yes">
</xsl:output>

<xsl:template match="/">
<xsl:apply-templates select="node()|@*"/>
</xsl:template>

<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>

<xsl:template match="/foohere">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
<xsl:copy-of select="document($foo)//"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>

Dhurandhar Bhatvadekar wrote:
Joe Kesselman wrote:
- for the portion that comes from foo.xml all occurrences of "${xyz}"
are replaced by "$".
You're inserting the contents of foo.xml into the stylesheet. That means
its contents are going to be interpreted as XSLT. Depending on where
these are occurring, they may be interpreted as Attribute Value Templates.

You may want to copy this using the document() function instead.

That's a great advice, thank you. I did not realize that the entity
resolution occurs *for the XSLT* and hence in effect, the XSLT is
modified. Let me take a look at the document() function and report
back.

Thank you, again.


--
() ASCII Ribbon Campaign | Joe Kesselman
/\ Stamp out HTML e-mail! | System architexture and kinetic poetry
Nov 8 '06 #4
Dhurandhar Bhatvadekar wrote:
Can you also tell me how to write out (template rule such that) an xml
element as-is, except that all the attributes should be sorted
lexically?
The order of attributes is explicitly NOT MEANINGFUL in XML, and XML
tools make absolutely no promises that order will be preserved. If order
is semantically important, you shoud use child elements rather than
attributes.

If the order matters for non-semantic reasons (for example, if you're
trying to do a simple text comparison between two XML files), you can
try looking for a tool that converts the XML into Canonical Form
(http://www.w3.org/TR/xml-c14n), and apply that after the stylesheet has
run. Or you could write your own XML serializer that outputs in
canonical form. Or you could find a solution that doesn't require
canonicalization, eg using an XML-aware file comparison tool.


--
() ASCII Ribbon Campaign | Joe Kesselman
/\ Stamp out HTML e-mail! | System architexture and kinetic poetry
Nov 8 '06 #5
By the way... If you really, absolutely, insist upon trying to order the
attributes using XSLT you could probably do it, but you'd have to
reimplement the XML serializer in XSLT and output in text mode. Very
emphatically NOT a recommended solution.

--
() ASCII Ribbon Campaign | Joe Kesselman
/\ Stamp out HTML e-mail! | System architexture and kinetic poetry
Nov 8 '06 #6

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

Similar topics

2
by: Andrew Degtiariov | last post by:
Hello! I tried to rewrite my python module in C. My module is successfully imported but i can't assing anything to class attributes (tp_setattr in PyTypeObject for class FlowReportRow filled up by...
1
by: David Manheim | last post by:
I am writing a module which is supposed to allow use of a set of attributes in any XML document; there is a DTD for XHTML, but it will need to work with all XML data types when imported. I have...
4
by: louissan | last post by:
Hi all, I'm coming across a problem, and really do not get where it comes from. The goal: to loop over attributes read from "object" nodes in an imported XML file/flow (via XMLHTTP) and...
0
by: Inna | last post by:
Hello all, I have DTS package that is importing data from multiple large Excel files from same directory into 1 database table. The structures are same and sizes of the .xls files are good. The...
16
by: John Salerno | last post by:
Let's say I'm making a game and I have this base class: class Character(object): def __init__(self, name, stats): self.name = name self.strength = stats self.dexterity = stats...
1
by: nitusa | last post by:
Hi All, First time poster, and newbie C# programmer so be patient with my ignorance. :) For my current project I need to store some information (install dir., file names, passwords, ect.) and...
26
by: tjhnson | last post by:
Hi, With properties, attributes and methods seem very similar. I was wondering what techniques people use to give clues to end users as to which 'things' are methods and which are attributes. ...
0
by: Kavitha Sudhershan | last post by:
hi, i wanna read the node values from xml. As per my code i can read the node values in first child node and for the next node am not able to read the node values. pls help me. i'll paste the code...
0
by: Nathan Sokalski | last post by:
I am attempting to add Attributes to my ASP.NET Controls & Properties. Here is what my Controls look like: <ToolboxData("<{0}:Parameter runat=""server""/>")_ Public Class Parameter : Inherits...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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...
0
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,...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.