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

S

stryder100

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.
 
M

Martin Honnen

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.
 
S

Stryder

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 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.

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 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.

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>"?>
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,053
Latest member
BrodieSola

Latest Threads

Top