[XML/XSL] Creating Variables

Pagina: 1
Acties:

  • didio
  • Registratie: Maart 2001
  • Laatst online: 01-04 09:19

didio

didio.nl

Topicstarter
Waarom werkt dit nou niet??
code:
1
2
3
4
5
6
7
8
<xsl:choose>
  <xsl:when test="text()">
    <xsl:variable name="aff_id">aff_id=<xsl:value-of select="text()"/>&amp;</xsl:variable>
  </xsl:when>
  <xsl:otherwise>
    <xsl:variable name="aff_id">&amp;</xsl:variable>
  </xsl:otherwise>
</xsl:choose>

Als ik nog extra tekst tussen de when en choose zet dan zie ik die text wel, dus hij kiest wel de ene of de andere.

Maar als ik nou de variable aanroep geeft ie deze error:

A reference to variable or parameter 'aff_id' cannot be resolved. The variable or parameter may not be defined, or it may not be in scope.

Ik roep de variable zo aan:
<form action="default.asp?{$aff_id}pg=1" method="post">

weinig tot niks..


  • mbravenboer
  • Registratie: Januari 2000
  • Laatst online: 06-11-2025
Een variabele heeft alleen een name en een select attribuut. De waarde van de variabele moet je dus opgeven in het attirbuut 'select'. De content is dus empty.

Hoe het met de scope van die variabele zit weet ik niet precies. Ik hoop voor je dat hij zo wel zichtbaar is buiten de choose :) .

Als ik jou was zou ik proberen om het onderscheid te maken op template match niveau (dus andere templates voor de beide gevallen).

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


  • mbravenboer
  • Registratie: Januari 2000
  • Laatst online: 06-11-2025
Zie trouwens de reference op http://www.zvon.org voor wat wel en niet mag. De XSLT reference daar geeft precies aan welke content waar is toegestaan :) .

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


  • didio
  • Registratie: Maart 2001
  • Laatst online: 01-04 09:19

didio

didio.nl

Topicstarter
Volgens mijn boek mag je volgens XSLT 1.0 een variable zo wel aanmaken.

stukje uit boek:
In XSLT 1.0, you didn't have to use the select attribute--you could enclose data inside the <xsl:variable> itself this way:

Maar volgens mij heeft het iets te maken dat hij de varible niet ziet, dat dacht ik ook al, maar waarom.. dat is de vraag.

Dat ik aparte templates aanmaak is eigenlijk niet te doen, omdat het een best groote template is en ik die variable meerdere malen nodig heb.

Ik zoek nog ff verder..

marcel.

weinig tot niks..


  • mbravenboer
  • Registratie: Januari 2000
  • Laatst online: 06-11-2025
Ah dat van die content klopt inderdaad nu ik het beter nakijk, sorry ;) .

Ik lees dit in de standaard over de scope van de variabele:
As well as being allowed at the top-level, both xsl:variable and xsl:param are also allowed in templates. xsl:variable is allowed anywhere within a template that an instruction is allowed. In this case, the binding is visible for all following siblings and their descendants. Note that the binding is not visible for the xsl:variable element itself. xsl:param is allowed as a child at the beginning of an xsl:template element. In this context, the binding is visible for all following siblings and their descendants.
bron: http://www.w3.org/TR/xslt#variables

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


  • didio
  • Registratie: Maart 2001
  • Laatst online: 01-04 09:19

didio

didio.nl

Topicstarter
Tja het gaat dus niet.. met xsl:if werkt het ook niet, heb ik net ff gechecked..

Het is ook niet zo heel erg, ik wilde querystrings opbouwen op die manier zodat je geen lege querystring krijgt..

weinig tot niks..

Pagina: 1