Hi Michael,

I've finally solved this problem implementing the extension as you suggested me in your early e-mail. On the contrary what I expected, to implement this functionality extension was quite easy and it took me less than an a hour. Thanks Saxon to be this great library!

For documentation purposes I will paste the extension function here for anyone who would have the same difficulties to get line number from a XML Beans DOM Tree inside the XSLT.

JAVA STATIC EXTENSION FUNCTION:

package br.pucrio.inf.serg.nclinspector.rulesengine.core.xslt;

import net.sf.saxon.dom.NodeWrapper;
import net.sf.saxon.expr.XPathContext;

import org.apache.xmlbeans.XmlBeans;
import org.apache.xmlbeans.XmlCursor;
import org.apache.xmlbeans.XmlLineNumber;
import org.w3c.dom.Node;

public class Functions {

    public static int lineNumber(XPathContext ctx) {
        XmlLineNumber bookmark = getBookmark(ctx);
        return bookmark.getLine();
    }

    public static int columnNumber(XPathContext ctx) {
        XmlLineNumber lineBookmark = getBookmark(ctx);
        return lineBookmark.getColumn();
    }

    private static XmlLineNumber getBookmark(XPathContext ctx) {
        NodeWrapper nodeWrapper = (NodeWrapper) ctx.getCurrentIterator()
                .current();

        Object underlyingNode = nodeWrapper.getUnderlyingNode();
        XmlCursor cursor = XmlBeans.nodeToCursor((Node) underlyingNode);
        XmlLineNumber bookmark = (XmlLineNumber) cursor
                .getBookmark(XmlLineNumber.class);
       
        return bookmark;
    }
}

AND THIS IS HOW TO USE THIS FUNCTION FROM A XSL:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:saxon="http://saxon.sf.net/"
    extension-element-prefixes="saxon"
    xmlns:insp="java:br.pucrio.inf.serg.nclinspector.rulesengine.core.xslt.Functions"
    xpath-default-namespace="http://www.ncl.org.br/NCL3.0/EDTVProfile">
     
    <xsl:template match="/ncl/head/regionBase">
        <result>
            <xsl:apply-templates/>
        </result>
    </xsl:template>
    <xsl:template match="region[@top][@bottom][@height]">
        <violation line="{insp:line-number()}" column="{insp:column-number()}" msgKey="topBottomHeight" severity="warning">
            <arg><xsl:value-of select="./@id"/></arg>
        </violation>
        <xsl:apply-templates/>
    </xsl:template>
    <xsl:template match="region[@left][@right][@width]">
        <violation line="{insp:line-number()}" column="{insp:column-number()}" msgKey="leftRightWidth" severity="warning">
            <arg><xsl:value-of select="./@id"/></arg>
        </violation>
        <xsl:apply-templates/>
    </xsl:template>
</xsl:stylesheet>


Thanks so much!
Gustavo Honorato


2009/12/2 Gustavo de Sá Carvalho Honorato <gustavohonorato@gmail.com>
Hi Michael,

I'm using Saxon-B as you suggested. But the returned line number by saxon:line-number was -1. I think it is because I'm using DOMSource created by XML Beans as source of XML document. There is any issue regarding this?

Thanks again,
Gustavo Honorato

On Tue, Dec 1, 2009 at 9:43 PM, Michael Kay <mike@saxonica.com> wrote:

 
Thanks again, but reimplement an already existent functionality will cost too much time for me :(. This project is part of my Master's degree and I just have a couple months to finish all this stuff and write my thesis. Is there any older version of Saxon which fits my needs without this time/money cost?

Thank you very much,
Gustavo Honorato

 
Yes, you're welcome to stick with Saxon-B 9.1 if it meets your needs. I'll stop fixing bugs in it at some stage but it will still be around.
 
Michael Kay
Saxonica 

------------------------------------------------------------------------------
Join us December 9, 2009 for the Red Hat Virtual Experience,
a free event focused on virtualization and cloud computing.
Attend in-depth sessions from your desk. Your couch. Anywhere.
http://p.sf.net/sfu/redhat-sfdev2dev

_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
saxon-help@lists.sourceforge.net

https://lists.sourceforge.net/lists/listinfo/saxon-help