Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

XSLT, XSL-FO, Creating a table to compare nodes 1

Status
Not open for further replies.

dseaver

IS-IT--Management
Jul 13, 2006
467
I have a list of legacy and current properties stored in an XML, there are 30+ properties, so I do not want to hard code each individual node possibility. I want the table to have the following structure

Code:
Property name| Current  | Legacy
PropA        | ValueCurr|ValueLeg
the properties are stored in the following format
Code:
<!--Bunch of other data-->
     <Properties Type="Current">
          <PropA>ValueCurr</PropA>
     </Properties>
     <Properties Type="Legacy">
          <PropA>ValueLeg</PropA>
     </Properties>
<!--Even more Data-->

Originally the data was in two different tables, but I need to have the values next to each other so that they can be checked against each other. Here is what I had to get each table before

Code:
<xsl:template match="Properties/@Type[.='Current']">
		<fo:block break-before="page" font-size="16pt" font-weight="bold"> 
			Properties - <xsl:value-of select="../@Type" />
		</fo:block>

		<fo:table  border="2pt solid black">
			<fo:table-column column-width="2.5in"/>
			<fo:table-column column-width="2.5in"/>
			
			<fo:table-body>	
				<fo:table-row>
					<fo:table-cell border="1pt solid black" font-weight="bold" font-size="12pt" padding="1pt">
						<fo:block>Property</fo:block>
					</fo:table-cell>
					<fo:table-cell border="1pt solid black" font-weight="bold" font-size="12pt" padding="1pt">
						<fo:block>Current</fo:block>
					</fo:table-cell >
					
				</fo:table-row>
				
				<xsl:apply-templates select="../child::node()" />
			</fo:table-body>
		</fo:table>
	</xsl:template>
	
	<xsl:template match="Properties/child::node()">
		<fo:table-row>
			<fo:table-cell border="1pt solid black" padding="1pt">
				<fo:block hyphenate="true"><xsl:value-of select="name()" /></fo:block>
			</fo:table-cell>
			<fo:table-cell border="1pt solid black" padding="1pt">
				<fo:block hyphenate="true"><xsl:value-of select="." /></fo:block>
			</fo:table-cell >
			
		</fo:table-row>
	</xsl:template>

I tried things like <xsl:value-of select="//Properties/@Type[.='Legacy']/name()" /> and similar others. Any help is greatly appreciated
 
Something like this (abbreviated)?
Code:
<xsl:for-each select="//Properties[@Type='Current']/*">
    <xsl:variable name="myName" select="name(.)"/>
    <xsl:value-of select="$myName"/><xsl:text> </xsl:text>
    <xsl:value-of select="."/><xsl:text> </xsl:text>
    <xsl:value-of select="ancestor::*[2]/Properties[@Type='Legacy']/*[name()=$myName]/."/><xsl:text> </xsl:text>
</xsl:for-each>
[small][COLOR=white red]Warning: typed, not tested![/color][/small]
This should reference a cousin node, which is a child of a node the Type attribute is 'Legacy', of the same name. (I have cousins with the same name, and it is very confusing at family reunions.)

Tom Morrison
 
After a little bit of tweaking, that worked perfectly. Here is what I ended up using.
Code:
<xsl:for-each select="../*">
					<fo:table-row>
						<xsl:variable name="myName" select="name(.)"/>
						<fo:table-cell border="1pt solid black" padding="1pt">
							<fo:block><xsl:value-of select="$myName"/></fo:block>
						</fo:table-cell>
						<fo:table-cell border="1pt solid black" padding="1pt">
							<fo:block><xsl:value-of select="."/></fo:block>
						</fo:table-cell>
						<fo:table-cell border="1pt solid black" padding="1pt">
							<fo:block><xsl:value-of select="ancestor::*[2]/Properties[@Type='Legacy']/*[name()=$myName]/."/></fo:block>
						</fo:table-cell>
					</fo:table-row>
				</xsl:for-each>
Thanks!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top