Search in sources :

Example 1 with CountersTable

use of org.apache.xalan.transformer.CountersTable in project j2objc by google.

the class ElemNumber method getCountString.

/**
 * Given an XML source node, get the count according to the
 * parameters set up by the xsl:number attributes.
 * @param transformer non-null reference to the the current transform-time state.
 * @param sourceNode The source node being counted.
 *
 * @return The count of nodes
 *
 * @throws TransformerException
 */
String getCountString(TransformerImpl transformer, int sourceNode) throws TransformerException {
    long[] list = null;
    XPathContext xctxt = transformer.getXPathContext();
    CountersTable ctable = transformer.getCountersTable();
    if (null != m_valueExpr) {
        XObject countObj = m_valueExpr.execute(xctxt, sourceNode, this);
        // According to Errata E24
        double d_count = java.lang.Math.floor(countObj.num() + 0.5);
        if (Double.isNaN(d_count))
            return "NaN";
        else if (d_count < 0 && Double.isInfinite(d_count))
            return "-Infinity";
        else if (Double.isInfinite(d_count))
            return "Infinity";
        else if (d_count == 0)
            return "0";
        else {
            long count = (long) d_count;
            list = new long[1];
            list[0] = count;
        }
    } else {
        if (Constants.NUMBERLEVEL_ANY == m_level) {
            list = new long[1];
            list[0] = ctable.countNode(xctxt, this, sourceNode);
        } else {
            NodeVector ancestors = getMatchingAncestors(xctxt, sourceNode, Constants.NUMBERLEVEL_SINGLE == m_level);
            int lastIndex = ancestors.size() - 1;
            if (lastIndex >= 0) {
                list = new long[lastIndex + 1];
                for (int i = lastIndex; i >= 0; i--) {
                    int target = ancestors.elementAt(i);
                    list[lastIndex - i] = ctable.countNode(xctxt, this, target);
                }
            }
        }
    }
    return (null != list) ? formatNumberList(transformer, list, sourceNode) : "";
}
Also used : NodeVector(org.apache.xml.utils.NodeVector) CountersTable(org.apache.xalan.transformer.CountersTable) XPathContext(org.apache.xpath.XPathContext) XObject(org.apache.xpath.objects.XObject)

Example 2 with CountersTable

use of org.apache.xalan.transformer.CountersTable in project robovm by robovm.

the class ElemNumber method getCountString.

/**
   * Given an XML source node, get the count according to the
   * parameters set up by the xsl:number attributes.
   * @param transformer non-null reference to the the current transform-time state.
   * @param sourceNode The source node being counted.
   *
   * @return The count of nodes
   *
   * @throws TransformerException
   */
String getCountString(TransformerImpl transformer, int sourceNode) throws TransformerException {
    long[] list = null;
    XPathContext xctxt = transformer.getXPathContext();
    CountersTable ctable = transformer.getCountersTable();
    if (null != m_valueExpr) {
        XObject countObj = m_valueExpr.execute(xctxt, sourceNode, this);
        //According to Errata E24
        double d_count = java.lang.Math.floor(countObj.num() + 0.5);
        if (Double.isNaN(d_count))
            return "NaN";
        else if (d_count < 0 && Double.isInfinite(d_count))
            return "-Infinity";
        else if (Double.isInfinite(d_count))
            return "Infinity";
        else if (d_count == 0)
            return "0";
        else {
            long count = (long) d_count;
            list = new long[1];
            list[0] = count;
        }
    } else {
        if (Constants.NUMBERLEVEL_ANY == m_level) {
            list = new long[1];
            list[0] = ctable.countNode(xctxt, this, sourceNode);
        } else {
            NodeVector ancestors = getMatchingAncestors(xctxt, sourceNode, Constants.NUMBERLEVEL_SINGLE == m_level);
            int lastIndex = ancestors.size() - 1;
            if (lastIndex >= 0) {
                list = new long[lastIndex + 1];
                for (int i = lastIndex; i >= 0; i--) {
                    int target = ancestors.elementAt(i);
                    list[lastIndex - i] = ctable.countNode(xctxt, this, target);
                }
            }
        }
    }
    return (null != list) ? formatNumberList(transformer, list, sourceNode) : "";
}
Also used : NodeVector(org.apache.xml.utils.NodeVector) CountersTable(org.apache.xalan.transformer.CountersTable) XPathContext(org.apache.xpath.XPathContext) XObject(org.apache.xpath.objects.XObject)

Aggregations

CountersTable (org.apache.xalan.transformer.CountersTable)2 NodeVector (org.apache.xml.utils.NodeVector)2 XPathContext (org.apache.xpath.XPathContext)2 XObject (org.apache.xpath.objects.XObject)2