XSL Transformatie

Pagina: 1
Acties:

  • -Klimaks-
  • Registratie: Maart 2001
  • Laatst online: 21-08 16:03
Ik moet hier een transformatie doen waar ik echt niet uitkom, ik heb het gevoel dat het echt een simpel dingetje is, maar ik kom er niet op.

XML document heeft volgende structuur
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<table>
    <resultline>
        <position>1</position>
    </resultline>
    <resultline>
        <position>2</position>
    </resultline>
    <resultline>
        <position>AVG</position>
    </resultline>
    <resultline>
        <position>3</position>
    </resultline>
...
</table>

De bedoeling is dat elke lijn waar de position gelijk is aan AVG in het vet komt te staan.

Momenteel heb ik het volgende:
code:
1
2
3
4
5
6
7
8
9
10
<xsl:template match="resultline">
       <xsl:choose>
                <xsl:when test="position='AVG'">
                             <b> En heel andere lap opmaakcode </b>
                </xsl:when>
                <xsl:otherwise>
                            nog eens die hele lap opmaakcode
                <xsl:otherwise>
        <xsl:choose>
...

Dit is niet echt wat je noemt een propere oplossing, en aangezien ik niet echt een held ben in XSL vroeg ik mij af hoe ik dit wel fatsoenlijk kan oplossen

In those days spirits were brave, the stakes were high, men were REAL men, women were REAL women, and small furry creatures from Alpha Centauri were REAL small furry creatures from Alpha Centauri.
Zaphod in The Hitchhikers Guide To The Galaxy


  • ari3
  • Registratie: Augustus 2002
  • Niet online
Ziet er op zich okee uit... Maar heb je wel iets dat het template voor resultline probeert toe te passen?`
zoals dit:
code:
1
<xsl:apply-templates/>

of dit:
code:
1
<xsl:apply-template select="resultline"/>

"Kill one man, and you are a murderer. Kill millions of men, and you are a conqueror. Kill them all, and you are a god." -- Jean Rostand


  • -Klimaks-
  • Registratie: Maart 2001
  • Laatst online: 21-08 16:03
Het werkt allemaal wel, tussen de when en de otherwise is maar een verschil : <b> en </b>. Al de rest er tussen is exact hetzelfde, dit maakt het niet alleen smerig imho, maar ook nog eens lastig om aan te passen (alles moet dubbel gebeuren)

In those days spirits were brave, the stakes were high, men were REAL men, women were REAL women, and small furry creatures from Alpha Centauri were REAL small furry creatures from Alpha Centauri.
Zaphod in The Hitchhikers Guide To The Galaxy


  • mbravenboer
  • Registratie: Januari 2000
  • Laatst online: 06-11-2025
Als ik je goed begrijp, gaat het met name om het voorkomen van duplicatie van die hele lap opmaakcode. Dat kan twee manieren.

Manier 1: modes
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
<xsl:template match="resultline">
   <xsl:apply-templates select="." mode="lap-opmaak-code"/>
</xsl:template>
 
<xsl:template match="resultline[text() = 'AVG']">
  <b>
    <xsl:apply-templates select="." mode="lap-opmaak-code"/>   
  </b>
</xsl:template>
 
<xsl:template match="resultline" mode="lap-opmaak-code">
    .....
</xsl:template>


Manier 2: maak een named template met de opmaak code en roep die aan.
http://www.w3.org/TR/xslt#named-templates

edit:
Moet vaker XSLT'en, allemaal tikfouten ;)

[ Voor 53% gewijzigd door mbravenboer op 06-05-2003 15:20 ]

Blog, Stratego/XT: Program Transformation, SDF: Syntax Definition, Nix: Software Deployment


  • -Klimaks-
  • Registratie: Maart 2001
  • Laatst online: 21-08 16:03
Bedankt, dat is helemaal wat ik zocht. Die named templates gaan me nog van pas komen :9

In those days spirits were brave, the stakes were high, men were REAL men, women were REAL women, and small furry creatures from Alpha Centauri were REAL small furry creatures from Alpha Centauri.
Zaphod in The Hitchhikers Guide To The Galaxy


Verwijderd

Ehm... kleine aanvulling op manier 1.

Zou het niet zoiets moeten zijn (xslt ook voor mij weer een tijd geleden), vooral de match op AVG klopt denk ik niet...

code:
1
2
3
4
5
6
7
8
9
10
11
12
13
<xsl:template match="resultline">
    <xsl:apply-templates select="." mode="lap-opmaak-code"/>
</xsl:template>

<xsl:template match="resultline[position = 'AVG']">
    <br>
    <xsl:apply-templates select="." mode="lap-opmaak-code"/>   
   <br>
</xsl:template>

<xsl:template match="resultline" mode="lap-opmaak-code">
      ..........
</xsl:template>


Just my two cents...

  • mbravenboer
  • Registratie: Januari 2000
  • Laatst online: 06-11-2025
voor die text() moest idd nog position staan ja.

Blog, Stratego/XT: Program Transformation, SDF: Syntax Definition, Nix: Software Deployment


  • -Klimaks-
  • Registratie: Maart 2001
  • Laatst online: 21-08 16:03
Het het uiteindelijk nog anders opgelost door aan de specifieke <tr> een class attribuut mee te geven en dan deze op te maken in CSS

In those days spirits were brave, the stakes were high, men were REAL men, women were REAL women, and small furry creatures from Alpha Centauri were REAL small furry creatures from Alpha Centauri.
Zaphod in The Hitchhikers Guide To The Galaxy

Pagina: 1