Black Friday = Pricewatch Bekijk onze selectie van de beste Black Friday-deals en voorkom een miskoop.

[XSL] Ongewilde xmlns-attributen van gedeclareerde namespace

Pagina: 1
Acties:
  • 155 views

  • r0bert
  • Registratie: September 2001
  • Laatst online: 30-07 02:32
Hoewel ik veel XSL topics in /13 vond via de search, denk ik dat deze oplossing toch meer in /14 zal liggen, zeker omdat ik mijn XSL/XML via PHP parse aan de serverside.

Ik heb volgens mij al mijn namespaces goed gedeclareerd, maar toch krijg ik alsnog rare output. Mijn input ziet er als volgt uit:

input:
XML:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<dataroot 
    xmlns:core="http://schema.domein.ext/" 
    xmlns:mysql="http://schema.domein.ext/mysql/" 
    xmlns:quotesns="http://schema.domein.ext/quotes/" 
    xmlns:quotesext="http://schema.domein.ext/quotesExtended/">
    
    <mysql:source id="1">
        <mysql:result xmlns:mysql="http://schema.domein.ext/mysql/" id="7">
            <mysql:set>
                <quotesns:quoteId xmlns="http://schema.domein.ext/quotes/">1</quotesns:quoteId>
                <quotesext:quoteTitle xmlns="http://schema.domein.ext/quotesExtended/">Testartikel</quotesext:quoteTitle>
            </mysql:set>
        </mysql:result>
    </mysql:source>
</dataroot>


Vervolgens transformeer ik het met XSL:

stylesheet
XML:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
<xsl:stylesheet  version="1.0"

        xmlns:core="http://schema.domein.ext/"
        xmlns:mysql="http://schema.domein.ext/mysql/"
        xmlns:quotesns="http://schema.domein.ext/quotes/"
        xmlns:quotesext="http://schema.domein.ext/quotesExtended/">
    
        <xsl:output method="xml" encoding="utf-8" omit-xml-declaration="no" />
        
        <xsl:template match="/">
            <core:root>                     
                <xsl:apply-templates />
            </core:root>
        </xsl:template>
        
        <xsl:template match="mysql:source">
            <xsl:apply-templates />
        </xsl:template>
        
        <xsl:template match="mysql:result">
            <xsl:for-each select="mysql:set">
                <xsl:copy-of select="*[1]" />
            </xsl:for-each>
        </xsl:template>
</xsl:stylesheet>


Ik heb de default namespaces weggelaten, omdat dat nogal eens voor problemen zorgt in XSL. Op zich is mijn output dan nog goed, maar daarna doe ik nog een transformatie. Mijn output van hierboven is:
Output:
XML:
1
2
3
4
<?xml version="1.0" encoding="utf-8"?>
<core:root xmlns:core="http://schema.domein.ext/" xmlns:mysql="http://schema.domein.ext/mysql/" xmlns:quotesns="http://schema.domein.ext/quotes/" xmlns:quotesext="http://schema.domein.ext/quotesExtended/">
  <quotesns:quoteId xmlns="http://schema.domein.ext/quotes/">1</quotesns:quoteId>
</core:root>


De stylesheet die ik vervolgens toepas hierop.
Stylesheet:
XML:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<xsl:stylesheet  version="1.0"

        xmlns:core="http://schema.domein.ext/"
        xmlns:mysql="http://schema.domein.ext/mysql/"
        xmlns:quotesns="http://schema.domein.ext/quotes/"
        xmlns:quotesext="http://schema.domein.ext/quotesExtended/">
        
        <xsl:output method="xml" encoding="utf-8" omit-xml-declaration="no" />
        
        <xsl:template match="/">
            <core:root>                                         
                <xsl:copy-of select="*[1]" />
            </core:root>
        </xsl:template>
        
</xsl:stylesheet>


Hierna is mijn output simpelweg belabbert:

Output:
XML:
1
2
3
4
5
6
7
8
<?xml version="1.0" encoding="utf-8"?>
<core:root xmlns:core="http://schema.domein.ext/" xmlns:mysql="http://schema.domein.ext/mysql/" xmlns:quotesns="http://schema.domein.ext/quotes/" xmlns:quotesext="http://schema.domein.ext/quotesExtended/">
  <core:buffer xmlns="http://schema.domein.ext/" xmlns:quotesns="http://schema.domein.ext/quotes/">
    <core:root xmlns:core="http://schema.domein.ext/" xmlns:mysql="http://schema.domein.ext/mysql/" xmlns:quotesns="http://schema.domein.ext/quotes/" xmlns:quotesext="http://schema.domein.ext/quotesExtended/">
      <quotesns:quoteId xmlns="http://schema.domein.ext/quotes/">1</quotesns:quoteId>
    </core:root>
  </core:buffer>
</core:root>


En dan bedoel ik m.n. de onnodige namespace declaraties overal. Is er een instelling wat ik moet veranderen in de parser? Of misschien een bug? Of moet ik het toch meer bij mijzelf zoeken? Ik heb via de search en Google veel pagina's gelezen, die met name focussen op de problemen met default-namespace, maar daar gaat het hier volgens mij niet om. Iemand ervaringen?

[ Voor 4% gewijzigd door r0bert op 02-08-2008 17:03 ]


  • NMe
  • Registratie: Februari 2004
  • Laatst online: 09-09 13:58

NMe

Quia Ego Sic Dico.

Hallo,

Ik heb dit topic even geleden geopend omdat ik echt niet verder kwam. Maar inmiddels kom ik er steeds meer achter dat de fout toch niet in de XSL zit maar serverside in de XSLT-parser constructor. Het topic kost mensen die me willen helpen daarom onondig tijd (denk ik) en daarom is het denk ik beter om het topic te verwijderen of op slot te doen. Mocht ik er dan alsnog echt niet uit komen, maak ik even een nieuw topic. Maar zo lijkt het inmiddels jammer van ieders tijd :)

Alvast bedankt,

Robert de Wilde
Overigens was het handiger geweest als je dat gewoon even gepost had, zodat niemand zijn tijd aan je topic zou verdoen in de tijd tussen die topic report en dit slotje. ;) Maar in elk geval bedankt dat je je medetweaker wil beschermen tegen verloren moeite. :)

'E's fighting in there!' he stuttered, grabbing the captain's arm.
'All by himself?' said the captain.
'No, with everyone!' shouted Nobby, hopping from one foot to the other.


Dit topic is gesloten.