Leave " alone in transformation

Discussion in 'XML' started by LionelAndJen@gmail.com, Nov 14, 2008.

  1. Guest

    I have an XML file that has a free form comment field in which the
    data provider, very kindly, already uses """ when writing
    "doesn't", I have doesn't .

    it's PERFECT, because that xml is then fed to an XSLT sheet that
    transforms this text into a sql insert statement. UNFORTUNATELY, XSLT
    translates doesn't into doesn't in the output, which then
    destroys my sql statement. How do I tell my XSLT to leave well-enough
    alone ? I know it has to be easy, but I just don't get it right now
    in spite of looking online.

    Also, bear in mind I'm your friendly neighborhood XSLT newbie. :)

    Thanks a lot.
     
    , Nov 14, 2008
    #1
    1. Advertising

  2. wrote:
    > I have an XML file that has a free form comment field in which the
    > data provider, very kindly, already uses """ when writing
    > "doesn't", I have doesn't .
    >
    > it's PERFECT, because that xml is then fed to an XSLT sheet that
    > transforms this text into a sql insert statement. UNFORTUNATELY, XSLT
    > translates doesn't into doesn't in the output, which then
    > destroys my sql statement. How do I tell my XSLT to leave well-enough
    > alone ? I know it has to be easy, but I just don't get it right now
    > in spite of looking online.


    No, it is not easy. You can't preserve entity references when parsing
    XML and using XSLT as the XSLT data model does not know any entity
    references. So XSLT uses an XML parser to build its data model, an input
    tree, and then transforms that input tree into a result tree. The result
    tree can then optionally be serialized as XML or HTML or plain text.
    If you want to ensure that certain characters are escaped with entity
    references in the output the XSLT processor creates then you need to
    look at processor specific extensions to do that. Or you can look into
    XSLT 2.0 and character maps http://www.w3.org/TR/xslt20/#character-maps.
    Note that both ways will not simply allow you to preserve entity
    references in the input, instead you will create entity references in
    the output.
    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
     
    Martin Honnen, Nov 15, 2008
    #2
    1. Advertising

  3. Joe Fawcett Guest

    "William F Hammond" <> wrote in message
    news:...
    > Martin Honnen <> writes:
    >
    >> wrote:

    > . . .
    >>> ... UNFORTUNATELY, XSLT
    >>> translates doesn&apos;t into doesn't in the output, which then
    >>> destroys my sql statement. How do I tell my XSLT to leave well-enough
    >>> alone ? ...

    > . . .
    >> references in the output the XSLT processor creates then you need to
    >> look at processor specific extensions to do that. Or you can look into
    >> XSLT 2.0 and character maps
    >> http://www.w3.org/TR/xslt20/#character-maps. Note that both ways will
    >> not simply allow you to preserve entity references in the input,
    >> instead you will create entity references in the output.

    >
    > I suppose sql language is not usually envisioned as a translation
    > target in the xml world.
    >

    I think it quite a common requirement though.
    I just do the usual sanitisation on the SQL though, replacing a single quote
    with two single quotes before running it.
    If the OP is is using XSLT 2.0 it's trivial with the replace function, if
    not there are plenty of example templates online that do string replacement.

    --

    Joe Fawcett
    http://joe.fawcett.name
     
    Joe Fawcett, Nov 21, 2008
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Phil Winstanley [Microsoft MVP ASP.NET]

    Re: validateRequest=&quot;false&quot; not working in web.config or page directive

    Phil Winstanley [Microsoft MVP ASP.NET], May 16, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    653
    Phil Winstanley [Microsoft MVP ASP.NET]
    May 16, 2004
  2. usr2003
    Replies:
    4
    Views:
    624
    usr2003
    Sep 19, 2003
  3. Frank Schmitt
    Replies:
    0
    Views:
    503
    Frank Schmitt
    Oct 14, 2003
  4. Ahti Legonkov
    Replies:
    0
    Views:
    519
    Ahti Legonkov
    Dec 12, 2003
  5. Replies:
    0
    Views:
    439
Loading...

Share This Page