xsl-list
[Top] [All Lists]

Re: [xsl] Getting a specific element count from a generic match

2006-04-10 11:10:46
Ok, working on getting some more information on the error,

The Exception.ToString:

"java.xml.transform.TransformerConfigurationException: Failed to
compile stylesheet. 1 error detected"

The Exception.StackTrace:

"at net.sf.saxon.PreparedStylesheet.prepare(Source styleSource)
at net.sf.saxon.TransformerFactoryImpl.newTemplates(Source source,
CompilerInfo info)
at Saxon.Api.XsltCompiler.Compile(Uri uri) ....."


Not sure if it helps or not, but here is the vb.net code I use:

        Public Sub Transform(ByVal xslDoc As String, ByVal xmlDoc As String, _
            ByVal output As String)


            'Create a New Processor instance
            Dim processor As New Processor
            'Load the source document
            Dim input As XdmNode =
processor.NewDocumentBuilder.Build(New Uri(xmlDoc))
            'Create the transformer for the stylesheet
            Dim transformer As XsltTransformer
            Try
                transformer = _
                    processor.NewXsltCompiler().Compile(New Uri(xslDoc)).Load()
            Catch ex As Exception
                MsgBox("Exception" & ex.ToString)
                MsgBox(ex.StackTrace)
                Throw New Exception(ex.Message)
            End Try

            'Set the root node of the source document to be the
initial context node
            transformer.InitialContextNode = input

            'Create the serializer
            Dim serializer As New Serializer
            Try
                serializer.SetOutputStream(New FileStream(output,
FileMode.Create, FileAccess.Write))
                'Transform the source XML
                transformer.Run(serializer)
            Catch ex As Exception
                Throw New Exception(ex.Message)
            Finally
                serializer = Nothing
            End Try

        End Sub


On 4/10/06, Michael Kay <mike(_at_)saxonica(_dot_)com> wrote:
When using the Saxon api the error message I'm getting back is "Failed
to compile stylesheet. 1 error detected". Figuring this wasn't quite
enough info to go on

You're doing something wrong in your API calls if you're not seeing the
error messages...

I ran it through stylus with Saxon 8.1.1, I get
"Required type of first argument of name() is node(); supplied value
has type xdt:anyAtomicType" on line 11 below:

When I change line 5 to  <xsl:variable name="namelist"
select="//*[not(name() = following::*/name())]"/> I still get an error
through Stylus, but it runs fine through .net.

8.1.1 was quite a long time ago, before node/name() was permitted by the
specs.

Michael Kay
http://www.saxonica.com/


1 <?xml version="1.0" encoding="utf-8"?>
2 <xsl:stylesheet version="2.0"
3 x mlns:xsl="http://www.w3.org/1999/XSL/Transform";>
4
5 <xsl:variable name="namelist"
select="distinct-values(//*/node-name())"/>
6
7  <xsl:variable name="root" select="/"/>
8
9 <xsl:template match="/">
10   <xsl:for-each select="$namelist">
11     <xsl:variable name="thisname" select="name()"/>
12     <name value="{$thisname}"
count="{count($root//*[name() = $thisname])}"/>
13   </xsl:for-each>
14 </xsl:template>
15
16 </xsl:stylesheet>

On 4/7/06, Jay Bryant <jay(_at_)bryantcs(_dot_)com> wrote:
Good one, Mike, and thanks for reminding me about distinct-values().

Jay Bryant
Bryant Communication Services

----- Original Message -----
From: "Michael Kay" <mike(_at_)saxonica(_dot_)com>
To: <xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com>
Sent: Friday, April 07, 2006 3:13 PM
Subject: RE: [xsl] Getting a specific element count from a
generic match



<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>

  <xsl:variable name="namelist" select="//*[not(name() =
following::*/name())]"/>


We're talking 2.0 here: you can get all the distinct names using

select="distinct-values(//*/node-name())"

That's O(n log n) rather than O(n^2), and it's also
namespace-aware.

Michael Kay
http://www.saxonica.com/




--~------------------------------------------------------------------
XSL-List info and archive:
http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: 
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--




--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: 
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: 
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--





--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: 
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--