Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > XSL character replace

Reply
Thread Tools

XSL character replace

 
 
Dominic
Guest
Posts: n/a
 
      04-28-2010
Hi there,

I'm dipping my toes into XSL and have used it a little in order to
remove the XML header of some XML which an API kept choking on (not
sure why TBH, seems an odd state of affairs that!). Now a different
API is choking on " (double quote - (HTML: ")) but is fine with
' (single quote (HTML: ')) for enclosing attributes. I've been
using a simple string replace to convert "s to 's (If you see what I
mean?) but have to convert the XML to a string rather than keep it as
XML. Is there an XSL way that'll do the same thing so that I can keep
the XML as XML?

Thanks in advance

Dom
 
Reply With Quote
 
 
 
 
Martin Honnen
Guest
Posts: n/a
 
      04-28-2010
Dominic wrote:

> I'm dipping my toes into XSL and have used it a little in order to
> remove the XML header of some XML which an API kept choking on (not
> sure why TBH, seems an odd state of affairs that!). Now a different
> API is choking on " (double quote - (HTML: ")) but is fine with
> ' (single quote (HTML: ')) for enclosing attributes. I've been
> using a simple string replace to convert "s to 's (If you see what I
> mean?) but have to convert the XML to a string rather than keep it as
> XML. Is there an XSL way that'll do the same thing so that I can keep
> the XML as XML?


Do you want to replace double quotes in character data (e.g. element or
attribute content)? Or do you want to replace double quotes in markup
(e.g. attribute value delimiters)?

But all that sounds rather odd, are those APIs that are choking really
APIs that are supposed to process XML?


--

Martin Honnen
http://msmvps.com/blogs/martin_honnen/
 
Reply With Quote
 
 
 
 
Dominic
Guest
Posts: n/a
 
      04-28-2010
On 28 Apr, 12:59, Martin Honnen <(E-Mail Removed)> wrote:
> Dominic wrote:
> > I'm dipping my toes into XSL and have used it a little in order to
> > remove the XML header of some XML which an API kept choking on (not
> > sure why TBH, seems an odd state of affairs that!). Now a different
> > API is choking on " (double quote - (HTML: ")) but is fine with
> > ' (single quote (HTML: ')) for enclosing attributes. I've been
> > using a simple string replace to convert "s to 's (If you see what I
> > mean?) but have to convert the XML to a string rather than keep it as
> > XML. Is there an XSL way that'll do the same thing so that I can keep
> > the XML as XML?

>
> Do you want to replace double quotes in character data (e.g. element or
> attribute content)? Or do you want to replace double quotes in markup
> (e.g. attribute value delimiters)?
>

I'm pretty sure that what I want is a way to convert the attribute
value delimiters rather than character data. If I'm understanding the
terminology correctly (always a possibility )
>
> But all that sounds rather odd, are those APIs that are choking really
> APIs that are supposed to process XML?
>

Believe it or not they are indeed! I had problems getting my head
around the concept as well but there you go...
>
> --
>
> * * * * Martin Honnen
> * * * *http://msmvps.com/blogs/martin_honnen/


To elaborate further:

What I'm after is something that'll convert this:

<something scheme="http://example.com" term="http://
anotherexample.org" />

into:

<something scheme='http://example.com' term='http://
anotherexample.org' />

Cheers for your reply,

Dom
 
Reply With Quote
 
Martin Honnen
Guest
Posts: n/a
 
      04-28-2010
Dominic wrote:

> To elaborate further:
>
> What I'm after is something that'll convert this:
>
> <something scheme="http://example.com" term="http://
> anotherexample.org" />
>
> into:
>
> <something scheme='http://example.com' term='http://
> anotherexample.org' />


But that is not something XSLT can do for you really, XSLT operates on a
tree model with nodes of type element, attribute (and others). That tree
model does not store the type of attribute value delimiters at all, and
the serialization of such a tree back to markup does not allow you to
define the attribute value delimiters either.

In the .NET world (where I am mostly at home when it comes to dealing
with XML programmatically) I would solve that with reading the XML in
with an XmlReader and feeding it back to an XmlTextWriter which has a
QuoteChar
http://msdn.microsoft.com/en-us/libr...v=VS.100).aspx
property that can be set.




--

Martin Honnen
http://msmvps.com/blogs/martin_honnen/
 
Reply With Quote
 
Dominic
Guest
Posts: n/a
 
      04-28-2010
On 28 Apr, 13:55, Martin Honnen <(E-Mail Removed)> wrote:
> Dominic wrote:
> > To elaborate further:

>
> > What I'm after is something that'll convert this:

>
> > <something scheme="http://example.com" term="http://
> > anotherexample.org" />

>
> > into:

>
> > <something scheme='http://example.com'term='http://
> > anotherexample.org' />

>
> But that is not something XSLT can do for you really, XSLT operates on a
> tree model with nodes of type element, attribute (and others). That tree
> model does not store the type of attribute value delimiters at all, and
> the serialization of such a tree back to markup does not allow you to
> define the attribute value delimiters either.
>
> In the .NET world (where I am mostly at home when it comes to dealing
> with XML programmatically) I would solve that with reading the XML in
> with an XmlReader and feeding it back to an XmlTextWriter which has a
> QuoteCharhttp://msdn.microsoft.com/en-us/library/system.xml.xmltextwriter..quot...
> property that can be set.
>
> --
>
> * * * * Martin Honnen
> * * * *http://msmvps.com/blogs/martin_honnen/


Cheers Martin,

I'm using PHP and can't seem to see anything similar in that language
which is why I was looking to XSL, if it's not possible though I'll
use my existing inelegant solution - at least it works even if
it's a bit of a cludge

Cool blog by the way, how do you get your XML coloured and formatted
so nicely? I usually do it by hand but it takes a fair old while.

Thanks again,

Dom
 
Reply With Quote
 
Peter Flynn
Guest
Posts: n/a
 
      04-28-2010
On Wed, 28 Apr 2010 14:55:28 +0200, Martin Honnen
<(E-Mail Removed)> wrote:
> Dominic wrote:



> > To elaborate further:
> >
> > What I'm after is something that'll convert this:
> >
> > <something scheme="http://example.com" term="http://
> > anotherexample.org" />
> >


If the software can't handle this, it is not XML-conformant and must
be replaced. You cannot rely on broken software to handle business
processes.

///Peter
 
Reply With Quote
 
Mayeul
Guest
Posts: n/a
 
      04-28-2010
Peter Flynn wrote:
> On Wed, 28 Apr 2010 14:55:28 +0200, Martin Honnen <(E-Mail Removed)>
> wrote:
>> Dominic wrote:

>
>
>> > To elaborate further:
>> > > What I'm after is something that'll convert this:
>> > > <something scheme="http://example.com" term="http://
>> > anotherexample.org" />
>> >

>
> If the software can't handle this, it is not XML-conformant and must be
> replaced. You cannot rely on broken software to handle business processes.
>


When you think of it, part of the point of XML is that this sort of
brokenness can be easily dealt with.

I'm more the type to heavily suggest upgrading to an XML-compliant
toolchain and offering assistance in doing so ;
/then/ if not accepted heavierly suggest against calling that XML within
technical communication, calling it something else myself anyway, and
offering to support this custom format for an additional fee. This
additional fee will enable me to make or update my own serializer, which
is easy to do and test.

Sure it looks like taking in the money without caring for added value to
the world. But it is also enabling your client to just do things
regardless of their utter incompetence with a technology known as XML.

--
Mayeul
 
Reply With Quote
 
Joe Kesselman
Guest
Posts: n/a
 
      04-29-2010
Hm. The right answer for what you've requested is an XML parser feeding
an XML serializer which uses ' to delimit attribute values. It might be
worth simply trying one of the parse-and-regenerate sample programs that
come with most XML parsers to see whether they have the desired effect.
I haven't seen one that exposes the selection of apostrophe versus quote
delimiters as an option; if you can't find one that is biased in the
direction you need, you may want to grab an open-source serializer and
tweak it.

(Trying to do this as string processing could mostly work, but will be
fragile in the presence of <[CDATA[]]> sections, so I tend to prefer the
parse-and-reserialize approach.)

XSLT manipulates document content, not syntax, and again don't generally
expose this as an option.

A properly written XML application should never see, or care about, this
distinction, so I'd make sure to hammer on whoever wrote the tool
consuming these documents and get them to fix their code as a service to
the community (and as a way of not losing customers), even if you have a
workaround for your own needs.


--
Joe Kesselman,
http://www.love-song-productions.com...lam/index.html

{} ASCII Ribbon Campaign | "may'ron DaroQbe'chugh vaj bIrIQbej" --
/\ Stamp out HTML mail! | "Put down the squeezebox & nobody gets hurt."
 
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
Replace /n with a XHTML <br /> using string.replace Alun ASP .Net 3 02-18-2008 05:52 AM
How can I replace all occurrences of a character with another character in std string? herman C++ 5 08-30-2007 09:05 AM
Re: [Pyrex] pyrex functions to replace a method (Re: replace a method Greg Ewing Python 2 06-29-2006 05:25 PM
pyrex functions to replace a method (Re: replace a method in class:how?) Brian Blais Python 1 06-27-2006 12:13 PM
XSL Question tp xsl:for-each and xsl:variable schaf@2wire.ch XML 1 05-27-2005 09:25 PM



Advertisments