[xsl] Getting position of parent

Subject: [xsl] Getting position of parent
From: Geoff Hankerson <ghank@xxxxxxxxxxx>
Date: Thu, 20 Feb 2003 09:05:41 -0600
I have the following xml which I am transforming into html. The xml was generated by a prcoess of converting pdf documents to svg then our own xml. The key is we retain information on the positioning of elements. Here is what it looks like:

<?xml version="1.0"?>
<Document Key="AB6B7E9ECC09C4E8FA99546A2280BD764" Title="New Document" Version="">
<Pages>
<Page Key="SF017E7CA7E03466C9BB5CF7148BD9DA3" Number="1" Height="15840" Width="12240" TopMargin="432" LeftMargin="720">
<Fields>
<Field Key="G04EC744D58B14D51A0F43BB69A675F38" Brand="3" DataTable="" DataField="" Equation="" Top="14460" Left="113" Height="150" Width="480" Backcolor="-2147483643" Forecolor="-2147483640" TabIndex="0" Display="-1" Publish="-1" FontFamily="Times New Roman" FontSize="6" FontBold="0" FontItalic="0" FontUnderline="0" FontStrikeout="0" Alignment="0">Form 6D </Field>
<Field Key="W3DAC72543D5F484ABF468D2AA3D519B0" Brand="3" DataTable="" DataField="" Equation="" Top="14598" Left="113" Height="150" Width="1440" Backcolor="-2147483643" Forecolor="-2147483640" TabIndex="0" Display="-1" Publish="-1" FontFamily="Times New Roman" FontSize="6" FontBold="0" FontItalic="0" FontUnderline="0" FontStrikeout="0" Alignment="0">Affidavit of Service by Mail </Field>
<Field Key="MF77FF6B80BD740D49D7C31C05032A85F" Brand="3" DataTable="" DataField="" Equation="" Top="-35" Left="113" Height="315" Width="2175" Backcolor="-2147483643" Forecolor="-2147483640" TabIndex="0" Display="-1" Publish="-1" FontFamily="Times New Roman" FontSize="14.25" FontBold="0" FontItalic="0" FontUnderline="0" FontStrikeout="0" Alignment="0">State of Minnesota </Field> <!-- etc., etc --> </Fields>
</Document>


So I use xsl to transform this to html using inline css for positioning, fonts info and the like. Here is the xsl:
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
<xsl:output method="html" media-type="print" encoding="unicode"/>
<xsl:variable name="pageHeight">1056</xsl:variable>
<xsl:template match="/">
<HTML>
<HEAD>
<TITLE><xsl:value-of select="/Document/@Title"/></TITLE>
</HEAD>


<BODY>
<xsl:apply-templates/> </BODY>
</HTML>
</xsl:template>
<xsl:template match="Field">
<div><xsl:attribute name="style">position:absolute;top:<xsl:value-of select="(@Top * 0.06666)"/>;left:<xsl:value-of select="@Left * 0.06666"/>;font-size:<xsl:value-of select="@FontSize"/>pt;font-family:<xsl:value-of select="@FontFamily"/>;</xsl:attribute><xsl:value-of select="."/></div>
</xsl:template>
</xsl:stylesheet>


Works great except for multipage documents will assume the "top" position is the same no matter if you are on the first or a subsequent page. So if the the text "Test Text" exists at top=400 left =400 on pages 1 and 2 the above xsl will just place them right on top of each other. So I came up with the idea of a page offset of 1056 pixels per page. So the only challenge is to figure out how to tell which page in the pages node you are on so that the top value can be calulated something like this <xsl:value-of select="(@Top * 0.06666) + ($pageNumber * $pageHeight)"/>.
So what I want to do is make $pageNumber = position() -1 for the page node while I am in the (grandchild) Field node. How can I accomplish this? I'm scratching my head on this one




XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list


Current Thread