In saxon XSLT, getting Content is not allowed in prolog, can't outputmarkup in a processing instruct

Discussion in 'XML' started by stryder100@gmail.com, Feb 25, 2009.

  1. Guest

    Hi. I'm processing a stylesheet with saxonb9-1-0-5j and am trying to
    output a processing instruction that has an exact copy of some markup
    in it. I'm running into the same problem whether I use the java
    version of SAXON on UNIX or the Windows/.Net version.

    Here's what I'm trying.

    <xsl:for-each select="//footnote">
    <xsl:processing-instruction name="footnote"><xsl:value-
    of select="."/></xsl:processing-instruction>
    </xsl:for-each>

    This doesn't give me what I want because I guess it applies the
    "default" template and just outputs the text as the body of the PI.
    However if I try to output parsed data as the body of the processing
    instruction using the saxon parse function like this...

    <xsl:for-each select="//footnote">
    <xsl:processing-instruction name="footnote"><xsl:value-
    of select="saxon:parse(.)"/></xsl:processing-instruction>
    </xsl:for-each>

    or even...

    <xsl:for-each select="//footnote">
    <xsl:processing-instruction name="footnote"
    select="saxon:parse(.)"/>
    </xsl:for-each>

    I get a runtime error "SXXP0003: Error reported by XML parser: Content
    is not allowed in prolog.". As I understand it the "prolog" is what
    occurs outside of the document element of an XML document, like a DTD
    declaration or an <?xml ... ?> declaration. But I'm trying to output
    this processing instruction inside the document element. It even
    gives me this error message when I just try and output this PI in
    place, right where the footnote is...

    <xsl:template match="footnote">
    <xsl:processing-instruction name="footnote"><xsl:value-of
    select="saxon:parse(.)"/></xsl:processing-instruction>
    </xsl:template>

    This gives me the "Content not allowed in prolog" error also, even
    though the <footnote> is inside the document element.

    According to http://www.w3.org/TR/REC-xml/#NT-Char there are no real
    limitations on what can be included as the body of a PI, certainly no
    exceptions that could possibly exist in a footnote's content.

    I've tried numerous other combinations using <xsl:copy>, <xsl:copy-
    of>, <xsl:variable>, <xsl:apply-templates>, all sorts of trickery to
    try and accomplish this to no avail.

    I'm able to output markup in a processing instruction if I define it
    literally, as in...

    <xsl:processing-instruction name="footnote">"&lt;tag&gt;here's some
    arbitrary data&lt;/tag&gt;"</xsl:processing-instruction>

    which outputs

    <?footnote "<tag>here's some arbitrary data</tag>"?>

    This suggests that technically I CAN put markup in the data in a
    processing instruction, I just can't put in parsed data from the
    document. Or something.

    If anyone knows a way to do it I'd be most appreciative.

    Thanks.
     
    , Feb 25, 2009
    #1
    1. Advertising

  2. Re: In saxon XSLT, getting Content is not allowed in prolog, can'toutput markup in a processing instruction.

    wrote:
    > Hi. I'm processing a stylesheet with saxonb9-1-0-5j and am trying to
    > output a processing instruction that has an exact copy of some markup
    > in it. I'm running into the same problem whether I use the java
    > version of SAXON on UNIX or the Windows/.Net version.
    >
    > Here's what I'm trying.
    >
    > <xsl:for-each select="//footnote">
    > <xsl:processing-instruction name="footnote"><xsl:value-
    > of select="."/></xsl:processing-instruction>
    > </xsl:for-each>
    >
    > This doesn't give me what I want because I guess it applies the
    > "default" template and just outputs the text as the body of the PI.


    In the above no default template is applied, indeed no template at all
    is applied. You just have a for-each outputting a processing instruction
    for each 'footnote' element.
    Thus if that does not do what you want you would better show us a
    minimal but complete XML input document and the transformation result
    you want to create from that input.
    So how do your 'footnote' elements in the XML input look exactly? And
    what kind of processing instructions do you want to generate from them?

    > I'm able to output markup in a processing instruction if I define it
    > literally, as in...
    >
    > <xsl:processing-instruction name="footnote">"&lt;tag&gt;here's some
    > arbitrary data&lt;/tag&gt;"</xsl:processing-instruction>
    >
    > which outputs
    >
    > <?footnote "<tag>here's some arbitrary data</tag>"?>
    >
    > This suggests that technically I CAN put markup in the data in a
    > processing instruction, I just can't put in parsed data from the
    > document. Or something.


    I don't know how the your 'footnote' elements look but it sounds as if
    you want to serialize nodes into a string of markup so saxon:serialize
    might do what you want:
    http://www.saxonica.com/documentation/extensions/functions/serialize.html

    But I am guessing, show us the XML input you have and the transformation
    result, then it is possible to tell how to achieve that.


    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
     
    Martin Honnen, Feb 25, 2009
    #2
    1. Advertising

  3. Stryder Guest

    Re: In saxon XSLT, getting Content is not allowed in prolog, can'toutput markup in a processing instruction.

    On Feb 25, 11:48 am, Martin Honnen <> wrote:
    > wrote:
    > > Hi.  I'm processing a stylesheet with saxonb9-1-0-5j and am trying to
    > > output a processing instruction that has an exact copy of some markup
    > > in it.  I'm running into the same problem whether I use the java
    > > version of SAXON on UNIX or the Windows/.Net version.

    >
    > > Here's what I'm trying.

    >
    > >             <xsl:for-each select="//footnote">
    > >                 <xsl:processing-instruction name="footnote"><xsl:value-
    > > of select="."/></xsl:processing-instruction>
    > >             </xsl:for-each>

    >
    > > This doesn't give me what I want because I guess it applies the
    > > "default" template and just outputs the text as the body of the PI.

    >
    > In the above no default template is applied, indeed no template at all
    > is applied. You just have a for-each outputting a processing instruction
    > for each 'footnote' element.
    > Thus if that does not do what you want you would better show us a
    > minimal but complete XML input document and the transformation result
    > you want to create from that input.
    > So how do your 'footnote' elements in the XML input look exactly? And
    > what kind of processing instructions do you want to generate from them?
    >
    > > I'm able to output markup in a processing instruction if I define it
    > > literally, as in...

    >
    > > <xsl:processing-instruction name="footnote">"&lt;tag&gt;here's some
    > > arbitrary data&lt;/tag&gt;"</xsl:processing-instruction>

    >
    > > which outputs

    >
    > > <?footnote "<tag>here's some arbitrary data</tag>"?>

    >
    > > This suggests that technically I CAN put markup in the data in a
    > > processing instruction, I just can't put in parsed data from the
    > > document.  Or something.

    >
    > I don't know how the your 'footnote' elements look but it sounds as if
    > you want to serialize nodes into a string of markup so saxon:serialize
    > might do what you want:http://www.saxonica.com/documentation/extensions/functions/serialize....
    >
    > But I am guessing, show us the XML input you have and the transformation
    > result, then it is possible to tell how to achieve that.
    >
    > --
    >
    >         Martin Honnen
    >        http://JavaScript.FAQTs.com/


    On Feb 25, 11:48 am, Martin Honnen <> wrote:
    > wrote:
    > > Hi. I'm processing a stylesheet with saxonb9-1-0-5j and am trying to
    > > output a processing instruction that has an exact copy of some markup
    > > in it. I'm running into the same problem whether I use the java
    > > version of SAXON on UNIX or the Windows/.Net version.

    >
    > > Here's what I'm trying.

    >
    > > <xsl:for-each select="//footnote">
    > > <xsl:processing-instruction name="footnote"><xsl:value-
    > > of select="."/></xsl:processing-instruction>
    > > </xsl:for-each>

    >
    > > This doesn't give me what I want because I guess it applies the
    > > "default" template and just outputs the text as the body of the PI.

    >
    > In the above no default template is applied, indeed no template at all
    > is applied. You just have a for-each outputting a processing instruction
    > for each 'footnote' element.
    > Thus if that does not do what you want you would better show us a
    > minimal but complete XML input document and the transformation result
    > you want to create from that input.
    > So how do your 'footnote' elements in the XML input look exactly? And
    > what kind of processing instructions do you want to generate from them?
    >
    > > I'm able to output markup in a processing instruction if I define it
    > > literally, as in...

    >
    > > <xsl:processing-instruction name="footnote">"&lt;tag&gt;here's some
    > > arbitrary data&lt;/tag&gt;"</xsl:processing-instruction>

    >
    > > which outputs

    >
    > > <?footnote "<tag>here's some arbitrary data</tag>"?>

    >
    > > This suggests that technically I CAN put markup in the data in a
    > > processing instruction, I just can't put in parsed data from the
    > > document. Or something.

    >
    > I don't know how the your 'footnote' elements look but it sounds as if
    > you want to serialize nodes into a string of markup so saxon:serialize
    > might do what you want:http://www.saxonica.com/documentation/extensions/functions/serialize....
    >
    > But I am guessing, show us the XML input you have and the transformation
    > result, then it is possible to tell how to achieve that.
    >
    > --
    >
    > Martin Honnen
    > http://JavaScript.FAQTs.com/


    Thanks Martin. saxon:serialize is just what I needed.

    In case this helps anyone else who comes across this thread, here's my
    input footnote, the XSLT I'm using to process it, and the output.
    Note that I'm also stripping newlines and multi-spaces with my XSLT
    because it's possible a <footnote> will have some indenting. Also a
    disclaimer - I probably wouldn't have designed things this way but
    like so many others I'm maintaining and extending someone else's code.

    Input:
    <footnote link-ref="fn1268661_1_ref" link-id="fn1268661_1"><p><sup>1</
    sup> Unless otherwise indicated, all section references are to the
    Internal Revenue Code in effect for the taxable year at issue, and all
    Rule references are to the Tax Court Rules of Practice and Procedure.</
    p></footnote>

    XSLT:
    <xsl:for-each select="//footnote">
    <xsl:processing-instruction
    name="footnote">"<xsl:value-of select="replace(replace(saxon:serialize
    (., 'serializer'), '
    ', ''), ' +', ' ')"/>"</xsl:processing-
    instruction>
    </xsl:for-each>

    Output:
    <?footnote "<footnote link-ref="fn1268661_1_ref" link-
    id="fn1268661_1"> <p> <sup>1</sup> Unless otherwise indicated, all
    section references are to the Internal Revenue Code in effect for the
    taxable year at issue, and all Rule references are to the Tax Court
    Rules of Practice and Procedure.</p> </footnote>"?>
     
    Stryder, Feb 25, 2009
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Scott Hopkins

    Content is not allowed in prolog

    Scott Hopkins, Apr 21, 2004, in forum: Java
    Replies:
    0
    Views:
    7,135
    Scott Hopkins
    Apr 21, 2004
  2. Nick
    Replies:
    0
    Views:
    3,207
  3. hazz
    Replies:
    6
    Views:
    49,632
    SkyUCHC
    Jun 9, 2010
  4. Dave Dubin

    [ANN] XML Processing in Prolog

    Dave Dubin, Jul 6, 2005, in forum: XML
    Replies:
    0
    Views:
    426
    Dave Dubin
    Jul 6, 2005
  5. Suresh Rajkumar
    Replies:
    3
    Views:
    177
    hengist podd
    Mar 24, 2009
Loading...

Share This Page