Add XSL stylesheet using Nokogiri

Hi there.

I am generating a XML file using Nokogiri. I would like to add a XSL
stylesheet reference to the document. By XSL stylesheet reference I mean

<?xsl-stylesheet type="text/xsl" href="foo.xsl"?>

I haven't found a way to do this with Nokogiri. Does anyone know a
solution to my problem? Any help is appreciated.

···

--
Posted via http://www.ruby-forum.com/.

···

On Fri, 2010-11-26 at 05:05 +0900, Hagbard Celine wrote:

Hi there.

I am generating a XML file using Nokogiri. I would like to add a XSL
stylesheet reference to the document. By XSL stylesheet reference I mean

<?xsl-stylesheet type="text/xsl" href="foo.xsl"?>

I haven't found a way to do this with Nokogiri. Does anyone know a
solution to my problem? Any help is appreciated.

Thank your very much. For some reason I wasn't able to find any material
about that issue through Google. Quite disappointing answer though.

···

--
Posted via http://www.ruby-forum.com/.

ruby - Associate an XML-Stylesheet with an XML Document with Nokogiri - Stack Overflow

OMG, there is so much fail here, I don't know where to start.

Instead, I will simply submit the correct method without further comment:

require "nokogiri"

doc = Nokogiri::XML "<root>foo</root>"
doc.root.add_previous_sibling Nokogiri::XML::ProcessingInstruction.new(doc,
"xml-stylesheet", 'type="text/xsl" href="foo.xsl"')
puts doc.to_xml
# => <?xml version="1.0"?>
# <?xml-stylesheet type="text/xsl" href="foo.xsl"?>
# <root>foo</root>

···

On Thu, Nov 25, 2010 at 3:09 PM, niklas | brueckenschlaeger < niklas@brueckenschlaeger.de> wrote:

On Fri, 2010-11-26 at 05:05 +0900, Hagbard Celine wrote:
> Hi there.
>
> I am generating a XML file using Nokogiri. I would like to add a XSL
> stylesheet reference to the document. By XSL stylesheet reference I mean
>
> <?xsl-stylesheet type="text/xsl" href="foo.xsl"?>
>
> I haven't found a way to do this with Nokogiri. Does anyone know a
> solution to my problem? Any help is appreciated.
>

Great. Thank you. I didn't know that.

···

On Mon, 2010-11-29 at 22:57 +0900, Mike Dalessio wrote:

On Thu, Nov 25, 2010 at 3:09 PM, niklas | brueckenschlaeger < > niklas@brueckenschlaeger.de> wrote:

>
> http://stackoverflow.com/questions/3166544/associate-an-xml-stylesheet-with-an-xml-document-with-nokogiri

OMG, there is so much fail here, I don't know where to start.

Instead, I will simply submit the correct method without further comment:

require "nokogiri"

doc = Nokogiri::XML "<root>foo</root>"
doc.root.add_previous_sibling Nokogiri::XML::ProcessingInstruction.new(doc,
"xml-stylesheet", 'type="text/xsl" href="foo.xsl"')
puts doc.to_xml
# => <?xml version="1.0"?>
# <?xml-stylesheet type="text/xsl" href="foo.xsl"?>
# <root>foo</root>

>
>
> On Fri, 2010-11-26 at 05:05 +0900, Hagbard Celine wrote:
> > Hi there.
> >
> > I am generating a XML file using Nokogiri. I would like to add a XSL
> > stylesheet reference to the document. By XSL stylesheet reference I mean
> >
> > <?xsl-stylesheet type="text/xsl" href="foo.xsl"?>
> >
> > I haven't found a way to do this with Nokogiri. Does anyone know a
> > solution to my problem? Any help is appreciated.
> >
>
>

I've added a section on PI nodes to nokogiri.org:

(see
https://github.com/flavorjones/nokogiri.org-tutorials/commit/8ccd0deff8dbe7fb0d12aa66521340596a673f0a
for
raw commit)

···

On Mon, Nov 29, 2010 at 9:17 AM, niklas | brueckenschlaeger < niklas@brueckenschlaeger.de> wrote:

Great. Thank you. I didn't know that.