0

Need to parse a XML file having something like this:

<Report xmlns="XXXXX"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="XXXXX https://www.somesite.com?x=3&y=4">
  <Tablix1><val>asdasdasd</val></Tablix1>
</Report>

on my XSL file i've got something like this:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
    xmlns:xsi="XXXXX">

<xsl:template match="/">
<xsl:value-of select="xsi:Report/xsi:Tablix1/xsi:val" />
</xsl:template>
</xsl:stylesheet>

can't seem to get this working because of the xml input having schemalocation a & within it...

Any clues on how to workaround it? I'm trying not to replace it before parsing...

  • Use `&` for `&` in XML. – kjhughes Feb 28 '19 at 17:33
  • There are a fair number of hits for "XSLT ampersand" here and on the web. What research have you done? –  Feb 28 '19 at 17:34
  • *"xml input having schemalocation a & within it..."* I don't see it. – michael.hor257k Feb 28 '19 at 17:50
  • Sorry @michael.hor257k: bad typo. `https://www.somesite.com?x=3&y=4`. Edited. – Pedro Correia Mar 01 '19 at 11:11
  • @kjhughes and @jdv : The `&` It's not a solution since I don't own the file. Making changes to it would be considered as a workaround, not a solution. I've made a fairly extensive research... – Pedro Correia Mar 01 '19 at 11:14
  • If that's your input document, you won't be able to process it using XSLT. You must escape the ampersand using some other method before it will accepted by an XML parser. If you're looking for a "solution", it's in the hands of the document provider. – michael.hor257k Mar 01 '19 at 12:00

1 Answers1

0

If the schema location is https://www.somesite.com?x=3&y=4 then it should be represented in XML as https://www.somesite.com?x=3&amp;y=4.

Michael Kay
  • 156,231
  • 11
  • 92
  • 164
  • Is there any way to go around changing the XML file? Anything I can do on XSL? For instance ignore the `schemaLocation` on the input? – Pedro Correia Mar 01 '19 at 11:16
  • If your input isn't well formed XML, then the only way you can process it is to use text-based tools that can handle non-XML input, for example tools such as sed/awk/perl. – Michael Kay Mar 01 '19 at 12:44