how to transform a processing-instruction with xml fragment inside

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

how to transform a processing-instruction with xml fragment inside

markus.sticker.epos

Hi,

 

I just want to ask: Is it possible to store a xml structure in a processing-instruction()?

Because this XML fragment is not part of the DTD.

And after the validation this “hidden” part will be read and also transformend?

 

The source

--------------8<-------------------------

<?xml version="1.0"?>

<?change <change><functionalChange><![CDATA[ghjgj]]></functionalChange><test><![CDATA[]]></test><testNotes><![CDATA[]]></testNotes><dependencies><![CDATA[]]></dependencies></change>?>

<XMLBlock>

<someText>Lorem ipsum dolor sit amet, consetetur ...</someText>

</XMLBlock>

-------------->8-------------------------

 

The XSLT

--------------8<-------------------------

<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"     xmlns:saxon="http://icl.com/saxon" version="1.1">

 

  <xsl:template match ="/">

    <xsl:variable name="change"><new:document xmlns:new="http://yournamescape.com/new" ><xsl:value-of select="saxon:node-set(processing-instruction('change'))" disable-output-escaping="yes"/></new:document></xsl:variable>

   

    <aaa>

      <xsl:copy-of select="$change"/>

      <bbb>

        <xsl:copy-of select="$change//*/*[local-name() = 'functionalChange']" />

      </bbb>

      <ccc>

        <xsl:copy-of select="saxon:node-set($change)/change/test" />

      </ccc>

      <ddd>

        <xsl:copy-of select="saxon:node-set($change)/change/testNotes" />

      </ddd>

    </aaa>

  </xsl:template>

   

</xsl:stylesheet>

-------------->8-------------------------

 

Kind regards

Markus Sticker

 


------------------------------------------------------------------------------

_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
[hidden email]
https://lists.sourceforge.net/lists/listinfo/saxon-help 
Reply | Threaded
Open this post in threaded view
|

Re: how to transform a processing-instruction with xml fragment inside

Michael Kay

On 5 Oct 2015, at 15:08, [hidden email] wrote:

Hi,

 

I just want to ask: Is it possible to store a xml structure in a processing-instruction()?


It’s possible, so long as the XML fragment doesn’t contain the character sequence “?>”. Whether it’s a good idea is another question. It’s more common to find CDATA being used for this purpose, though that is equally questionable.

If you want to process XML that has been hidden from the XML parser in this way (either as a PI or as CDATA), you will need to parse it from the XSLT. The XPath 3.0 function parse-xml() or the Saxon extension function saxon:parse() can be used for this purpose.

saxon:node-set() and exslt:node-set() do not parse XML, they were designed to convert a “result tree fragment” to a node-set. This is a meaningless operation in 2.0 and 3.0 because result tree fragments no longer exist.

Michael Kay
Saxonica


Because this XML fragment is not part of the DTD.

And after the validation this “hidden” part will be read and also transformend?

 

The source

--------------8<-------------------------

<?xml version="1.0"?>

<?change <change><functionalChange><![CDATA[ghjgj]]></functionalChange><test><![CDATA[]]></test><testNotes><![CDATA[]]></testNotes><dependencies><![CDATA[]]></dependencies></change>?>

<XMLBlock>

<someText>Lorem ipsum dolor sit amet, consetetur ...</someText>

</XMLBlock>

-------------->8-------------------------

 

The XSLT

--------------8<-------------------------

<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"     xmlns:saxon="http://icl.com/saxon" version="1.1">

 

  <xsl:template match ="/">

    <xsl:variable name="change"><new:document xmlns:new="http://yournamescape.com/new" ><xsl:value-of select="saxon:node-set(processing-instruction('change'))" disable-output-escaping="yes"/></new:document></xsl:variable>

   

    <aaa>

      <xsl:copy-of select="$change"/>

      <bbb>

        <xsl:copy-of select="$change//*/*[local-name() = 'functionalChange']" />

      </bbb>

      <ccc>

        <xsl:copy-of select="saxon:node-set($change)/change/test" />

      </ccc>

      <ddd>

        <xsl:copy-of select="saxon:node-set($change)/change/testNotes" />

      </ddd>

    </aaa>

  </xsl:template>

   

</xsl:stylesheet>

-------------->8-------------------------

 

Kind regards

Markus Sticker

 

------------------------------------------------------------------------------
_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
[hidden email]
https://lists.sourceforge.net/lists/listinfo/saxon-help


------------------------------------------------------------------------------

_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
[hidden email]
https://lists.sourceforge.net/lists/listinfo/saxon-help