[XPath] Referenzen auf Elemente innerhalb eines node tests

Zatic

Erfahrenes Mitglied
Hallo community,

Ich moechte in einer Schleife den Wert des gerade betrachteten Elements als Vergleichswert in einem node test eines anderen Elements verwenden. Die entsprechenden Zeilen sind im Template "studentsEnlisted" im angehanegten XSL Dokument zu sehen (ganz am Ende).

Der relevante Ausschnitt (gekuerzt):
HTML:
<xsl:for-each select="studentlist/student">
                <!-- funkioniert: -->
		<xsl:value-of select="self::value()"/>
                <!-- funkioniert: -->
		<xsl:value-of select="."/>
                <!-- funkioniert: -->
		<xsl:value-of select="//user[@id = '1']/firstname"/>

                <!-- leer: -->		                      
		<xsl:value-of select="id(.)/firstname"/>
                <!-- leer: -->		
		<xsl:value-of select="//user[@id = .]/firstname"/>
                <!-- leer: -->		
		<xsl:value-of select="//user[@id = self::value()]/firstname"/>
</xsl:for-each>

Es soll also der Wert des aktuellen Kontextes der Schleife, also der Wert von 'student', als Vergleichswert im node test "[//user@id = ]" verwendet werden. Der node test gibt allerdings ein leeres node set zurueck.

Daraus kann ich mir keinen Reim machen. Verwende ich hier die falsche Syntax?

Verwendeter Prozessor ist Xalan.

Viele Gruesse,
Manuel


Das Quell-Dokument:

HTML:
<distribution startdate="" enddate="">
	<tutorials>
		<tutorial id="23" course="1" instructor="17" 
		startdate="2006-11-03 10:30" enddate="2006-11-03 10:40" 
		lowerbound="10" upperbound="30">
			<description>Java 101</description>
			<room>R4.404</room>
			<studentlist>
				<student>1</student>
				<student>2</student>
				<student>3</student>
				<student>4</student>
			</studentlist>
		</tutorial>
	</tutorials>

	<courses>
		<course id="1" startdate="" enddate="">
			<title>Java 101</title>
			<description>Java Grundlagen</description>
		</course>
	</courses>

	
	<users>
		<user id="17">
			<firstname>Daniel</firstname>
			<lastname>Duesentrieb</lastname>
			<emailaddress>daniel@duesentrieb.com</emailaddress>
		</user>
		<user id="1">
			<firstname>Manuel</firstname>
			<lastname>Fuchs</lastname>
			<emailaddress>manuelfuchs@mail.comn</emailaddress>
		</user>
		<user id="2">
			<firstname>Matthias</firstname>
			<lastname>Heinz</lastname>
			<emailaddress>matthias@heinz.com</emailaddress>
		</user>
		<user id="3">
			<firstname>Hannah</firstname>
			<lastname>Heider</lastname>
			<emailaddress>hannah@heider.com</emailaddress>
		</user>
		<user id="4">
			<firstname>Iris</firstname>
			<lastname>Auge</lastname>
			<emailaddress>iris@gmx.de</emailaddress>
		</user>
	</users>
</distribution>

Das komplette XSL Dokument:
HTML:
<xsl:stylesheet version="1.0" 
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
	xmlns:fo="http://www.w3.org/1999/XSL/Format">
<xsl:output method="xml" version="1.0" encoding="UTF-8" 
	indent="yes" omit-xml-declaration="no" 
	standalone="yes" media-type="application/xml+fo"/>
	<!-- 
		Root template, defines master page layout
		and page sequence. Calls page builder template
	 -->
	<xsl:template match="/distribution/tutorials/tutorial">
		<fo:root >
		  <fo:layout-master-set>
		    <fo:simple-page-master master-name="main" 
		      margin-top="16pt" margin-bottom="36pt" 
		      page-width="8.5in" page-height="11in" 
		      margin-left="72pt" margin-right="72pt">
		      <fo:region-body margin-bottom="50pt" margin-top="50pt"/>
		    </fo:simple-page-master>
		  </fo:layout-master-set>
		  <fo:page-sequence master-reference="main">
		    <fo:flow flow-name="xsl-region-body">
		    		<xsl:call-template name="buildPage"/>
		    </fo:flow>
		  </fo:page-sequence>	  	
		</fo:root>
	</xsl:template>

	<!-- 
		Structere of one page. There is at least one page per Tutorial,
		meaning that there is not data on one page that belongs to 
		different tutorials.
		Calls 3 templates which build the page's main region: 
		header = logo and heading
		tutorialData = metadata, like room or lecturer
		studentsEnlisted = table of students and their email addresses
	 -->
	<xsl:template name="buildPage" match="tutorial">
		<xsl:call-template name="header"/>	
		<xsl:call-template name="tutorialData"/>	 
		<fo:block space-after="0.5cm" font-size="14pt">
			Teilnehmerliste:
		</fo:block>
		<xsl:call-template name="studentsEnlisted"/>		
	</xsl:template>	

	<!-- 
		Header-template: The projects logo an a haeding
	 -->
	<xsl:template name="header" match="tutorial">
		<fo:block  break-before="page" >
	      	<fo:external-graphic width="100pt" height="100pt" 
	      	content-width="80pt" content-height="80pt" 
	      	src="/home/mes/workspace/PdfExportTest/WebContent/Yi_80.png"/>
	    </fo:block>
	      
	    <fo:block text-decoration="underline" text-indent="-0.1cm" font-weight="bold" 
	      font-size="20pt" line-height="17pt">
			Tutorial  
			<fo:inline keep-together.within-line="always"><fo:leader rule-thickness="2pt"
	leader-length="100%" leader-pattern="rule"/></fo:inline>    	
	    </fo:block>
	</xsl:template>

	<!-- 
		Template for tutorial data. Displays:
		 * Lecturer
		 * Room
		 * Course
	 -->
	<xsl:template match="tutorial" name="tutorialData">
		<fo:table space-after="1cm" space-before="1cm" border-collapse="collapse"  
		font-size="12pt" font-family="sans-serif" font-style="italic">
	    	<fo:table-column column-width="30%"/>
	  		<fo:table-column column-width="70%"/>    
	    	<fo:table-body >
		        <fo:table-row>    
		            <fo:table-cell padding="5pt" >
		                <fo:block>Kurs: </fo:block>
		            </fo:table-cell>
		            <fo:table-cell padding="5pt" >
		                <fo:block font-style="normal" 
		                font-weight="bold"><xsl:value-of 
		                select="//course[@id = //@course]/title" />
		                </fo:block>
		            </fo:table-cell>
		        </fo:table-row>   
		        <fo:table-row>    
		            <fo:table-cell padding="5pt" >
		            <fo:block> </fo:block>
		            </fo:table-cell>
		            <fo:table-cell padding="5pt" >
		                <fo:block font-style="normal">
		                <xsl:value-of select="//course[@id = //@course]/description" />
		                </fo:block>
		            </fo:table-cell>
		        </fo:table-row>            
		        <fo:table-row>    
		            <fo:table-cell padding="5pt" >
		                <fo:block>Dozent: </fo:block>
		            </fo:table-cell>
		            <fo:table-cell padding="5pt" >
		                <fo:block font-style="normal" font-weight="bold">
		                 <xsl:value-of select="//user[@id = //@instructor]/firstname" />
		                 <xsl:text> </xsl:text>
		                 <xsl:value-of select="//user[@id = //@instructor]/lastname" />
		                </fo:block>
		            </fo:table-cell>
		        </fo:table-row>   
		        <fo:table-row>    
		            <fo:table-cell padding="5pt" >
		                <fo:block>Raum: </fo:block>
		            </fo:table-cell>
		            <fo:table-cell padding="5pt" >
		                <fo:block font-style="normal" 
		                 font-weight="bold"><xsl:value-of select="room" /></fo:block>
		            </fo:table-cell>
		        </fo:table-row>  
		        -->		                      
		    </fo:table-body>
		</fo:table>
	</xsl:template>
	
	<!-- 
		Table of students that are enlisted for that tutorial.
		Table consists of two columns, one for the student's name,
		one for the e-mail address. 
		Rows are colored alternating.
	 -->
	 
	  
	<xsl:template match="tutorial" name="studentsEnlisted">
		 <fo:table  border-collapse="collapse"  font-size="12pt" font-family="sans-serif" 
		       font-style="italic">
		    <fo:table-column column-width="50%"/>
		  	<fo:table-column column-width="50%"/>    
		    <fo:table-body >
		    	<xsl:for-each select="studentlist/student">
		        <fo:table-row>
					<xsl:attribute name="background-color"><xsl:choose><xsl:when 
					test="position() mod 2 =0">rgb(255,255,255)</xsl:when><xsl:otherwise>rgb(230,230,230)</xsl:otherwise></xsl:choose></xsl:attribute>        
		            <fo:table-cell padding="5pt" border="1pt solid darkgrey">
		                <fo:block>
                <!-- funkioniert: -->
		<xsl:value-of select="self::value()"/>
                <!-- funkioniert: -->
		<xsl:value-of select="."/>
                <!-- funkioniert: -->
		<xsl:value-of select="//user[@id = '1']/firstname"/>

                <!-- leer: -->		                      
		<xsl:value-of select="id(.)/firstname"/>
                <!-- leer: -->		
		<xsl:value-of select="//user[@id = .]/firstname"/>
                <!-- leer: -->		
		<xsl:value-of select="//user[@id = self::value()]/firstname"/>
		                </fo:block>
		            </fo:table-cell>
		            <fo:table-cell padding="5pt" border="1pt solid darkgrey">
		                <fo:block font-style="normal"><fo:basic-link  color="blue" text-decoration="underline">
		                <xsl:attribute name="external-destination">mailto:<xsl:value-of select="email"/></xsl:attribute> 
		                     <xsl:value-of select="email"/></fo:basic-link></fo:block>
		            </fo:table-cell>
		        </fo:table-row>        
		        </xsl:for-each>
		    </fo:table-body>
		</fo:table>
	</xsl:template>

</xsl:stylesheet>
 
Zurück