Thanx for the reply(ies)

-position() doesn't work for me (it always returns '1' for the first child
of a node but i've to know the absolute position inside the whole xml tree)
-preceding-sibling::*/@* looks better i'll try it out

For clarifications:
I try to display the content an xml file in ONE table using a generic xsl
stylesheet.
So I've neither a node name nor a knowledge about the xml structure (has a
node attributes, is it a text node ...).
For now it should work at least for each xml file wich has ONE root node.

I start with the root node (naturally), list all Attributes of the current
selected node by recursive call, then list all childs also by recursive call
and so on.
Therefore I've to know if I've to color this row or not (see below):

(WHITE BG)      root
(GRAY BG)               child
(WHITE BG)                      attr1
(GRAY BG)                       attr2
(WHITE BG)                      attr3
(GRAY BG)               child2
(WHITE BG)                      grandchild1
(GRAY BG)                               attr1
(WHITE BG)                      grandchild2
(GRAY BG)               child3.....

ps>I've attached the xsl. If anyone has time to look in it....
...any comments/proposals etc. are very welcome

cu Torsten

> -----Original Message-----
> From: David Neary [mailto:[EMAIL PROTECTED]
> Sent: Donnerstag, 15. Mai 2003 11:43
> To: '[EMAIL PROTECTED]'
> Subject: RE: XPath expression
>
>
>
> De : Torsten Erler [mailto:[EMAIL PROTECTED]
> > I know it's not the right List, but I think there are a lot
> of XSL-Experts
> here in this list.
>
> You might want to try the xsl-list at
> http://www.mulberrytech.com/xsl/xsl-list
>
> > Does anyone know the XPath expression for counting all
> Attributes and all
> childs (grandchilds...) > of all preceding siblings of the
> selected node???
>
> count(preceding-sibling::*/@* | preceding-sibling::*/*)
>
> > In Other words which row number has the selected node in a
> full expanded
> tree.
> > (I need this to set the row backgound color for each second row)
>
> I don't understand the relationship between question 1 and
> question 2...
>
> For the second question, you just need something like this...
>
> <xsl:apply-templates select="row"/>
>
> <xsl:template match="row">
>   <xsl:choose>
>     <xsl:when test="position() % 2 = 0">
>       <!-- Even row -->
>     </xsl:when>
>     <xsl:otherwise>
>       <!-- odd row -->
>     </xsl:otherwise>
>   </xsl:choose>
> </xsl:template>
>
> You should use the context nodeset to do the hard work for
> you - otherwise
> you're going to enormously beef up your processing time.
>
> By the way, please excuse the mail formatting if it's yucky -
> I haven't
> quite figured out how to make Outlook behave properly.
>
> Cheers,
> Dave.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; xmlns:fo="http://www.w3.org/1999/XSL/Format"; version="1.0" xmlns:xalan="http://xml.apache.org/xslt";>
	<!--geometry parameter list (passing in per  java code)-->
	<xsl:param name="page-height"/>
	<xsl:param name="page-width"/>
	<xsl:param name="margin-bottom"/>
	<xsl:param name="margin-top"/>
	<xsl:param name="margin-left"/>
	<xsl:param name="margin-right"/>
	<xsl:param name="font-family"/>
	<xsl:param name="language"/>
	
	<xsl:variable name="lineHighlightColor">rgb(220,220,220)</xsl:variable>
	
	<xsl:output method="xml" indent="yes" xalan:indent-amount="4"/>
	<xsl:strip-space elements="*"/>

<!--
Copyright (c) 2003 by net-linx All rights reserved
content template describes all data from xml in a table-like strukture
Author: Torsten Erler
-->

	<xsl:template match="*">
		<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format";>
			<!--********************** Layout Master ******************************-->
			<fo:layout-master-set>
				<fo:simple-page-master master-reference="A4" page-width="{$page-width}pt" page-height="{$page-height}pt" margin-bottom="{$margin-bottom}pt" margin-top="{$margin-top}pt" margin-left="{$margin-left}pt" margin-right="{$margin-right}pt">
					<fo:region-before extent="0pt"/>
					<fo:region-body margin-top="0pt" margin-bottom="0pt"/>
					<fo:region-after extent="0pt"/>
				</fo:simple-page-master>
			</fo:layout-master-set>
			<!--********************** End Layout Master ************************-->
			<fo:page-sequence master-name="A4">
				<fo:flow flow-name="xsl-region-body">
					<fo:table table-layout="fixed" inline-progression-dimension.optimum="100%" font-family="{$font-family}" font-size="9pt">
						<fo:table-column column-width="proportional-column-width(3)"/>
						<fo:table-column column-width="proportional-column-width(4)"/>
						<fo:table-column column-width="proportional-column-width(2)"/>
						<fo:table-column column-width="proportional-column-width(5)"/>
						<fo:table-header border-style="solid" border-width="1pt" background-color="black" color="white" font-weight="bold">
							<fo:table-row>
								<fo:table-cell border-right="solid" padding="3pt">
									<fo:block>Entry</fo:block>
								</fo:table-cell>
								<fo:table-cell border-right="solid" padding="3pt">
									<fo:block>X-Path Expression</fo:block>
								</fo:table-cell>
								<fo:table-cell border-right="solid" padding="3pt">
									<fo:block>Type</fo:block>
								</fo:table-cell>
								<fo:table-cell padding="3pt">
									<fo:block>Value</fo:block>
								</fo:table-cell>
							</fo:table-row>
						</fo:table-header>
						<fo:table-body>
							<!-- call  the template first for the root node -->
							<xsl:call-template name="show_node">
								<xsl:with-param name="lineCount">0</xsl:with-param>
								<xsl:with-param name="indent">0</xsl:with-param>
								<xsl:with-param name="type">Root Element</xsl:with-param>
								<xsl:with-param name="xPath"><xsl:value-of select="name(.)"/></xsl:with-param>
								<xsl:with-param name="indent">0</xsl:with-param>
								<xsl:with-param name="fontWeight">bold</xsl:with-param>
								<xsl:with-param name="fontSize">12pt</xsl:with-param>
							</xsl:call-template>
						</fo:table-body>
					</fo:table>
				</fo:flow>
			</fo:page-sequence>
		</fo:root>
	</xsl:template>
	
	
	<!-- iterate down through the xml structure, with recusive call to this template  -->
	<xsl:template name="show_node" match=".">
	<!-- node description parameters -->
	<xsl:param name="indent"/>
	<xsl:param name="type"/>
	<xsl:param name="xPath"/>
	<xsl:param name="lineCount"/>
	<xsl:param name="fontStyle"/>
	<xsl:param name="fontWeight"/>
	<xsl:param name="fontSize"/>
		
		<fo:table-row>
				
<xsl:if test="$lineCount mod 2 = 1 ">
			<xsl:attribute name="background-color">
				<xsl:value-of select="$lineHighlightColor"/>
			</xsl:attribute>
</xsl:if>		
			<fo:table-cell font-size="{$fontSize}" font-weight="{$fontWeight}" padding="3pt" border-left="solid">
<xsl:if test="$fontStyle != '' ">
	<xsl:attribute name="font-style"><xsl:value-of select="$fontStyle"/></xsl:attribute>
</xsl:if>
				<fo:block text-indent="{concat($indent, 'pt')}"><xsl:value-of select="name(.)"/></fo:block>
			</fo:table-cell>
			<fo:table-cell padding="3pt">
				 <fo:block><xsl:value-of select=" $xPath"/></fo:block>
			</fo:table-cell>
			<fo:table-cell padding="3pt">
				<fo:block><xsl:value-of select="$type"/></fo:block>
			</fo:table-cell>
			
<xsl:if test="text()">			
			<fo:table-cell padding="3pt"  white-space-collapse="false">
				<fo:block><xsl:value-of select="."/></fo:block>
			</fo:table-cell>			
</xsl:if>						
			
		</fo:table-row>
		
		<!-- list all attributes  -->
		<xsl:for-each select="@*">
			<xsl:call-template name="show_node">
				<xsl:with-param name="indent"><xsl:value-of select="$indent + 4"/></xsl:with-param>
				<xsl:with-param name="type">Attribute</xsl:with-param>
				<xsl:with-param name="xPath">
					<xsl:value-of select="$xPath"/>/@<xsl:value-of select="name(.)"/>
				</xsl:with-param>
				<xsl:with-param name="lineCount">
					<xsl:value-of select="$lineCount + position()"/>
				</xsl:with-param>
				<xsl:with-param name="fontStyle">italic</xsl:with-param>
				<xsl:with-param name="fontWeight">normal</xsl:with-param>
				<xsl:with-param name="fontSize">inherit</xsl:with-param>
			</xsl:call-template>
		</xsl:for-each>
		
		<!-- list all child nodes  -->
		<xsl:for-each select="./*">
			<xsl:call-template name="show_node">
				<xsl:with-param name="indent"><xsl:value-of select="$indent + 4"/></xsl:with-param>
				<xsl:with-param name="type">
				<xsl:choose>
					<!-- pass as parameters a description of the node    -->
					<xsl:when test="text()">Text</xsl:when>
					<xsl:when test="comment()">Comment</xsl:when>
					<xsl:when test="processing-instruction()">Processing Instruction</xsl:when>
					<xsl:otherwise>Element</xsl:otherwise>
				</xsl:choose>				
				</xsl:with-param>
				<xsl:with-param name="xPath">
					<xsl:value-of select="$xPath"/>/<xsl:value-of select="name(.)"/>
				</xsl:with-param>
				<xsl:with-param name="lineCount">
					<xsl:value-of select="$lineCount + position() + count(preceding-sibling::*/@*)"/>
				</xsl:with-param>
				<xsl:with-param name="fontWeight">normal</xsl:with-param>
				<xsl:with-param name="fontSize">inherit</xsl:with-param>
			</xsl:call-template>
		</xsl:for-each>
		
	</xsl:template>
</xsl:stylesheet>

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to