How do I serialize output from a node-set in xslt 1.0? Unicorn Meta Zoo #1: Why another podcast? Announcing the arrival of Valued Associate #679: Cesar Manara Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!How can I check which XSLT processor is being used in Solr?How do I generate a comma-separated list with XSLT/XPath?XSLT: Using copy-of to output xmlConvert 'embedded' XML doc into CDATA output in XSLT (1.0)Escaping xml tag in XSLTGenerating C# code from XML: how to output '<' and '>'?Need help xslt 1.0 grouping for mapping stylesheetGeneric XSLT 1.0 to convert XML on some specific node pathXSLT 1.0 Stylesheet is duplicating data in outputOutputting XML structure using XSLTHow to transform CDATA format from one xml to another?

Is this homebrew racial feat, Stonehide, balanced?

Are these square matrices always diagonalisable?

Passing args from the bash script to the function in the script

Expansion//Explosion and Siren Stormtamer

Arriving in Atlanta after US Preclearance in Dublin. Will I go through TSA security in Atlanta to transfer to a connecting flight?

std::is_constructible on incomplete types

How to translate "red flag" into Spanish?

"Whatever a Russian does, they end up making the Kalashnikov gun"? Are there any similar proverbs in English?

All ASCII characters with a given bit count

Co-worker works way more than he should

"My boss was furious with me and I have been fired" vs. "My boss was furious with me and I was fired"

Israeli soda type drink

My admission is revoked after accepting the admission offer

What's parked in Mil Moscow helicopter plant?

Did the Roman Empire have penal colonies?

What is the least dense liquid under normal conditions?

Map material from china not allowed to leave the country

Why did Israel vote against lifting the American embargo on Cuba?

What is this word supposed to be?

What is /etc/mtab in Linux?

Is Bran literally the world's memory?

A strange hotel

What is the term for a person whose job is to place products on shelves in stores?

What do you call the part of a novel that is not dialog?



How do I serialize output from a node-set in xslt 1.0?



Unicorn Meta Zoo #1: Why another podcast?
Announcing the arrival of Valued Associate #679: Cesar Manara
Data science time! April 2019 and salary with experience
The Ask Question Wizard is Live!How can I check which XSLT processor is being used in Solr?How do I generate a comma-separated list with XSLT/XPath?XSLT: Using copy-of to output xmlConvert 'embedded' XML doc into CDATA output in XSLT (1.0)Escaping xml tag in XSLTGenerating C# code from XML: how to output '<' and '>'?Need help xslt 1.0 grouping for mapping stylesheetGeneric XSLT 1.0 to convert XML on some specific node pathXSLT 1.0 Stylesheet is duplicating data in outputOutputting XML structure using XSLTHow to transform CDATA format from one xml to another?



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















I am working with some XML inside of XSLT. I want to save a section of it in a content node. I left the CDATA node out of this example.



When I grab the xml like this it's escaped ie. &lt; = <



<content name="test”>
<xsl:copy-of select="//content[@name='something']/node()" />
</content>


But I need to do some processing on the data before I store it in a content node. I have an xsl:for-each call and it loops saving sections. However, when I call a similar command I can't get the XML to escape.



<xsl:for-each select="exsl:node-set($xml)//data">
<content name="test">
<xsl:copy-of select="./node()" />
</content>


I've put CDATA nodes around it and outputted the content, but then I have issues in the system with double escaping. I really need this copy-of call to output escaped XML.



I really want something like:



<content name="test">
&lt;data&gt;Some data&lt;data&gt;
</content>


Input would be something like this:



<root>
<data>Some data</data>
<data>more data</data>
</root>


This a simplification of the data. There would be additional xml nodes in the data node.










share|improve this question
























  • When it comes to CDATA and "escaped XML" is better to show input/stylesheet/desired-output because people tend to refer to very different things in this topic.

    – Alejandro
    Mar 22 at 15:49











  • updated. I really just want the special characters escaped. <>"

    – Joshua Hedges
    Mar 22 at 15:55











  • What's your input ?

    – Vebbie
    Mar 22 at 15:59











  • It looks like your are stringifying a document fragment to be consumed by another application that doesn't understand XML. Without the input source it's dificult to tell. My advise is to remove the offending application from the chain.

    – Alejandro
    Mar 22 at 16:10











  • I put in some mock input. I think it has something to do with the call to exsl:node-set($xml)

    – Joshua Hedges
    Mar 22 at 16:14

















0















I am working with some XML inside of XSLT. I want to save a section of it in a content node. I left the CDATA node out of this example.



When I grab the xml like this it's escaped ie. &lt; = <



<content name="test”>
<xsl:copy-of select="//content[@name='something']/node()" />
</content>


But I need to do some processing on the data before I store it in a content node. I have an xsl:for-each call and it loops saving sections. However, when I call a similar command I can't get the XML to escape.



<xsl:for-each select="exsl:node-set($xml)//data">
<content name="test">
<xsl:copy-of select="./node()" />
</content>


I've put CDATA nodes around it and outputted the content, but then I have issues in the system with double escaping. I really need this copy-of call to output escaped XML.



I really want something like:



<content name="test">
&lt;data&gt;Some data&lt;data&gt;
</content>


Input would be something like this:



<root>
<data>Some data</data>
<data>more data</data>
</root>


This a simplification of the data. There would be additional xml nodes in the data node.










share|improve this question
























  • When it comes to CDATA and "escaped XML" is better to show input/stylesheet/desired-output because people tend to refer to very different things in this topic.

    – Alejandro
    Mar 22 at 15:49











  • updated. I really just want the special characters escaped. <>"

    – Joshua Hedges
    Mar 22 at 15:55











  • What's your input ?

    – Vebbie
    Mar 22 at 15:59











  • It looks like your are stringifying a document fragment to be consumed by another application that doesn't understand XML. Without the input source it's dificult to tell. My advise is to remove the offending application from the chain.

    – Alejandro
    Mar 22 at 16:10











  • I put in some mock input. I think it has something to do with the call to exsl:node-set($xml)

    – Joshua Hedges
    Mar 22 at 16:14













0












0








0








I am working with some XML inside of XSLT. I want to save a section of it in a content node. I left the CDATA node out of this example.



When I grab the xml like this it's escaped ie. &lt; = <



<content name="test”>
<xsl:copy-of select="//content[@name='something']/node()" />
</content>


But I need to do some processing on the data before I store it in a content node. I have an xsl:for-each call and it loops saving sections. However, when I call a similar command I can't get the XML to escape.



<xsl:for-each select="exsl:node-set($xml)//data">
<content name="test">
<xsl:copy-of select="./node()" />
</content>


I've put CDATA nodes around it and outputted the content, but then I have issues in the system with double escaping. I really need this copy-of call to output escaped XML.



I really want something like:



<content name="test">
&lt;data&gt;Some data&lt;data&gt;
</content>


Input would be something like this:



<root>
<data>Some data</data>
<data>more data</data>
</root>


This a simplification of the data. There would be additional xml nodes in the data node.










share|improve this question
















I am working with some XML inside of XSLT. I want to save a section of it in a content node. I left the CDATA node out of this example.



When I grab the xml like this it's escaped ie. &lt; = <



<content name="test”>
<xsl:copy-of select="//content[@name='something']/node()" />
</content>


But I need to do some processing on the data before I store it in a content node. I have an xsl:for-each call and it loops saving sections. However, when I call a similar command I can't get the XML to escape.



<xsl:for-each select="exsl:node-set($xml)//data">
<content name="test">
<xsl:copy-of select="./node()" />
</content>


I've put CDATA nodes around it and outputted the content, but then I have issues in the system with double escaping. I really need this copy-of call to output escaped XML.



I really want something like:



<content name="test">
&lt;data&gt;Some data&lt;data&gt;
</content>


Input would be something like this:



<root>
<data>Some data</data>
<data>more data</data>
</root>


This a simplification of the data. There would be additional xml nodes in the data node.







xml xslt






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 22 at 20:08







Joshua Hedges

















asked Mar 22 at 15:35









Joshua HedgesJoshua Hedges

8610




8610












  • When it comes to CDATA and "escaped XML" is better to show input/stylesheet/desired-output because people tend to refer to very different things in this topic.

    – Alejandro
    Mar 22 at 15:49











  • updated. I really just want the special characters escaped. <>"

    – Joshua Hedges
    Mar 22 at 15:55











  • What's your input ?

    – Vebbie
    Mar 22 at 15:59











  • It looks like your are stringifying a document fragment to be consumed by another application that doesn't understand XML. Without the input source it's dificult to tell. My advise is to remove the offending application from the chain.

    – Alejandro
    Mar 22 at 16:10











  • I put in some mock input. I think it has something to do with the call to exsl:node-set($xml)

    – Joshua Hedges
    Mar 22 at 16:14

















  • When it comes to CDATA and "escaped XML" is better to show input/stylesheet/desired-output because people tend to refer to very different things in this topic.

    – Alejandro
    Mar 22 at 15:49











  • updated. I really just want the special characters escaped. <>"

    – Joshua Hedges
    Mar 22 at 15:55











  • What's your input ?

    – Vebbie
    Mar 22 at 15:59











  • It looks like your are stringifying a document fragment to be consumed by another application that doesn't understand XML. Without the input source it's dificult to tell. My advise is to remove the offending application from the chain.

    – Alejandro
    Mar 22 at 16:10











  • I put in some mock input. I think it has something to do with the call to exsl:node-set($xml)

    – Joshua Hedges
    Mar 22 at 16:14
















When it comes to CDATA and "escaped XML" is better to show input/stylesheet/desired-output because people tend to refer to very different things in this topic.

– Alejandro
Mar 22 at 15:49





When it comes to CDATA and "escaped XML" is better to show input/stylesheet/desired-output because people tend to refer to very different things in this topic.

– Alejandro
Mar 22 at 15:49













updated. I really just want the special characters escaped. <>"

– Joshua Hedges
Mar 22 at 15:55





updated. I really just want the special characters escaped. <>"

– Joshua Hedges
Mar 22 at 15:55













What's your input ?

– Vebbie
Mar 22 at 15:59





What's your input ?

– Vebbie
Mar 22 at 15:59













It looks like your are stringifying a document fragment to be consumed by another application that doesn't understand XML. Without the input source it's dificult to tell. My advise is to remove the offending application from the chain.

– Alejandro
Mar 22 at 16:10





It looks like your are stringifying a document fragment to be consumed by another application that doesn't understand XML. Without the input source it's dificult to tell. My advise is to remove the offending application from the chain.

– Alejandro
Mar 22 at 16:10













I put in some mock input. I think it has something to do with the call to exsl:node-set($xml)

– Joshua Hedges
Mar 22 at 16:14





I put in some mock input. I think it has something to do with the call to exsl:node-set($xml)

– Joshua Hedges
Mar 22 at 16:14












1 Answer
1






active

oldest

votes


















2














Evan Lenz has an XSLT 1 based implementation of XML serialization at http://lenzconsulting.com/xml-to-string/: if you use that you have e.g.



<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">

<xsl:import href="http://lenzconsulting.com/xml-to-string/xml-to-string.xsl"/>

<xsl:output indent="yes" cdata-section-elements="content"/>

<xsl:template match="/">
<xsl:apply-templates/>
</xsl:template>

<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>

<xsl:template match="data">
<content>
<xsl:apply-templates select="." mode="xml-to-string"/>
</content>
</xsl:template>

</xsl:stylesheet>


https://xsltfiddle.liberty-development.net/pPzifpn/4



If the processor is libxslt then it might allow you to implement an extension function, for instance PHP allows you to call PHP functions and the DOMDocument in PHP has a saveXML function to serialize, so you can call that from XSLT:



<?php

function serializeNode($node)
return $node[0]->ownerDocument->saveXML($node[0]);


$xml = <<<EOT
<root>
<data>Some data</data>
<data>more data</data>
</root>
EOT;

$xsl = <<<EOT
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:php="http://php.net/xsl"
exclude-result-prefixes="php"
version="1.0">

<xsl:output indent="yes" cdata-section-elements="content"/>

<xsl:template match="/">
<xsl:apply-templates/>
</xsl:template>

<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>

<xsl:template match="data">
<content>
<xsl:value-of select="php:function('serializeNode', .)"/>
</content>
</xsl:template>

</xsl:stylesheet>
EOT;

$doc = new DOMDocument();
$doc->loadXML($xml);

$proc = new XSLTProcessor();
$proc->registerPHPFunctions('serializeNode');

$sheet = new DOMDocument();
$sheet->loadXML($xsl);

$proc->importStylesheet($sheet);

echo $proc->transformToXml($doc);

?>





share|improve this answer

























  • I appreciate the answer but with my requirements it's complicated for me to use code from a 3rd party.

    – Joshua Hedges
    Mar 22 at 18:11






  • 1





    Using code from an answer of StackOverflow would not be using code from a 3rd party? Anyway, try to find out whether the processor/enviroment has any extension function to solve that or easily allows you to write one that performs the serialization.

    – Martin Honnen
    Mar 22 at 19:03











  • From Evan Lenz copyright notice: Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:... keep, reproduce the notice and don't make claims about Evan endorsement

    – Alejandro
    Mar 22 at 19:22











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55303127%2fhow-do-i-serialize-output-from-a-node-set-in-xslt-1-0%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









2














Evan Lenz has an XSLT 1 based implementation of XML serialization at http://lenzconsulting.com/xml-to-string/: if you use that you have e.g.



<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">

<xsl:import href="http://lenzconsulting.com/xml-to-string/xml-to-string.xsl"/>

<xsl:output indent="yes" cdata-section-elements="content"/>

<xsl:template match="/">
<xsl:apply-templates/>
</xsl:template>

<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>

<xsl:template match="data">
<content>
<xsl:apply-templates select="." mode="xml-to-string"/>
</content>
</xsl:template>

</xsl:stylesheet>


https://xsltfiddle.liberty-development.net/pPzifpn/4



If the processor is libxslt then it might allow you to implement an extension function, for instance PHP allows you to call PHP functions and the DOMDocument in PHP has a saveXML function to serialize, so you can call that from XSLT:



<?php

function serializeNode($node)
return $node[0]->ownerDocument->saveXML($node[0]);


$xml = <<<EOT
<root>
<data>Some data</data>
<data>more data</data>
</root>
EOT;

$xsl = <<<EOT
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:php="http://php.net/xsl"
exclude-result-prefixes="php"
version="1.0">

<xsl:output indent="yes" cdata-section-elements="content"/>

<xsl:template match="/">
<xsl:apply-templates/>
</xsl:template>

<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>

<xsl:template match="data">
<content>
<xsl:value-of select="php:function('serializeNode', .)"/>
</content>
</xsl:template>

</xsl:stylesheet>
EOT;

$doc = new DOMDocument();
$doc->loadXML($xml);

$proc = new XSLTProcessor();
$proc->registerPHPFunctions('serializeNode');

$sheet = new DOMDocument();
$sheet->loadXML($xsl);

$proc->importStylesheet($sheet);

echo $proc->transformToXml($doc);

?>





share|improve this answer

























  • I appreciate the answer but with my requirements it's complicated for me to use code from a 3rd party.

    – Joshua Hedges
    Mar 22 at 18:11






  • 1





    Using code from an answer of StackOverflow would not be using code from a 3rd party? Anyway, try to find out whether the processor/enviroment has any extension function to solve that or easily allows you to write one that performs the serialization.

    – Martin Honnen
    Mar 22 at 19:03











  • From Evan Lenz copyright notice: Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:... keep, reproduce the notice and don't make claims about Evan endorsement

    – Alejandro
    Mar 22 at 19:22















2














Evan Lenz has an XSLT 1 based implementation of XML serialization at http://lenzconsulting.com/xml-to-string/: if you use that you have e.g.



<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">

<xsl:import href="http://lenzconsulting.com/xml-to-string/xml-to-string.xsl"/>

<xsl:output indent="yes" cdata-section-elements="content"/>

<xsl:template match="/">
<xsl:apply-templates/>
</xsl:template>

<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>

<xsl:template match="data">
<content>
<xsl:apply-templates select="." mode="xml-to-string"/>
</content>
</xsl:template>

</xsl:stylesheet>


https://xsltfiddle.liberty-development.net/pPzifpn/4



If the processor is libxslt then it might allow you to implement an extension function, for instance PHP allows you to call PHP functions and the DOMDocument in PHP has a saveXML function to serialize, so you can call that from XSLT:



<?php

function serializeNode($node)
return $node[0]->ownerDocument->saveXML($node[0]);


$xml = <<<EOT
<root>
<data>Some data</data>
<data>more data</data>
</root>
EOT;

$xsl = <<<EOT
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:php="http://php.net/xsl"
exclude-result-prefixes="php"
version="1.0">

<xsl:output indent="yes" cdata-section-elements="content"/>

<xsl:template match="/">
<xsl:apply-templates/>
</xsl:template>

<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>

<xsl:template match="data">
<content>
<xsl:value-of select="php:function('serializeNode', .)"/>
</content>
</xsl:template>

</xsl:stylesheet>
EOT;

$doc = new DOMDocument();
$doc->loadXML($xml);

$proc = new XSLTProcessor();
$proc->registerPHPFunctions('serializeNode');

$sheet = new DOMDocument();
$sheet->loadXML($xsl);

$proc->importStylesheet($sheet);

echo $proc->transformToXml($doc);

?>





share|improve this answer

























  • I appreciate the answer but with my requirements it's complicated for me to use code from a 3rd party.

    – Joshua Hedges
    Mar 22 at 18:11






  • 1





    Using code from an answer of StackOverflow would not be using code from a 3rd party? Anyway, try to find out whether the processor/enviroment has any extension function to solve that or easily allows you to write one that performs the serialization.

    – Martin Honnen
    Mar 22 at 19:03











  • From Evan Lenz copyright notice: Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:... keep, reproduce the notice and don't make claims about Evan endorsement

    – Alejandro
    Mar 22 at 19:22













2












2








2







Evan Lenz has an XSLT 1 based implementation of XML serialization at http://lenzconsulting.com/xml-to-string/: if you use that you have e.g.



<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">

<xsl:import href="http://lenzconsulting.com/xml-to-string/xml-to-string.xsl"/>

<xsl:output indent="yes" cdata-section-elements="content"/>

<xsl:template match="/">
<xsl:apply-templates/>
</xsl:template>

<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>

<xsl:template match="data">
<content>
<xsl:apply-templates select="." mode="xml-to-string"/>
</content>
</xsl:template>

</xsl:stylesheet>


https://xsltfiddle.liberty-development.net/pPzifpn/4



If the processor is libxslt then it might allow you to implement an extension function, for instance PHP allows you to call PHP functions and the DOMDocument in PHP has a saveXML function to serialize, so you can call that from XSLT:



<?php

function serializeNode($node)
return $node[0]->ownerDocument->saveXML($node[0]);


$xml = <<<EOT
<root>
<data>Some data</data>
<data>more data</data>
</root>
EOT;

$xsl = <<<EOT
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:php="http://php.net/xsl"
exclude-result-prefixes="php"
version="1.0">

<xsl:output indent="yes" cdata-section-elements="content"/>

<xsl:template match="/">
<xsl:apply-templates/>
</xsl:template>

<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>

<xsl:template match="data">
<content>
<xsl:value-of select="php:function('serializeNode', .)"/>
</content>
</xsl:template>

</xsl:stylesheet>
EOT;

$doc = new DOMDocument();
$doc->loadXML($xml);

$proc = new XSLTProcessor();
$proc->registerPHPFunctions('serializeNode');

$sheet = new DOMDocument();
$sheet->loadXML($xsl);

$proc->importStylesheet($sheet);

echo $proc->transformToXml($doc);

?>





share|improve this answer















Evan Lenz has an XSLT 1 based implementation of XML serialization at http://lenzconsulting.com/xml-to-string/: if you use that you have e.g.



<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">

<xsl:import href="http://lenzconsulting.com/xml-to-string/xml-to-string.xsl"/>

<xsl:output indent="yes" cdata-section-elements="content"/>

<xsl:template match="/">
<xsl:apply-templates/>
</xsl:template>

<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>

<xsl:template match="data">
<content>
<xsl:apply-templates select="." mode="xml-to-string"/>
</content>
</xsl:template>

</xsl:stylesheet>


https://xsltfiddle.liberty-development.net/pPzifpn/4



If the processor is libxslt then it might allow you to implement an extension function, for instance PHP allows you to call PHP functions and the DOMDocument in PHP has a saveXML function to serialize, so you can call that from XSLT:



<?php

function serializeNode($node)
return $node[0]->ownerDocument->saveXML($node[0]);


$xml = <<<EOT
<root>
<data>Some data</data>
<data>more data</data>
</root>
EOT;

$xsl = <<<EOT
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:php="http://php.net/xsl"
exclude-result-prefixes="php"
version="1.0">

<xsl:output indent="yes" cdata-section-elements="content"/>

<xsl:template match="/">
<xsl:apply-templates/>
</xsl:template>

<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>

<xsl:template match="data">
<content>
<xsl:value-of select="php:function('serializeNode', .)"/>
</content>
</xsl:template>

</xsl:stylesheet>
EOT;

$doc = new DOMDocument();
$doc->loadXML($xml);

$proc = new XSLTProcessor();
$proc->registerPHPFunctions('serializeNode');

$sheet = new DOMDocument();
$sheet->loadXML($xsl);

$proc->importStylesheet($sheet);

echo $proc->transformToXml($doc);

?>






share|improve this answer














share|improve this answer



share|improve this answer








edited Mar 24 at 13:47

























answered Mar 22 at 16:39









Martin HonnenMartin Honnen

114k66279




114k66279












  • I appreciate the answer but with my requirements it's complicated for me to use code from a 3rd party.

    – Joshua Hedges
    Mar 22 at 18:11






  • 1





    Using code from an answer of StackOverflow would not be using code from a 3rd party? Anyway, try to find out whether the processor/enviroment has any extension function to solve that or easily allows you to write one that performs the serialization.

    – Martin Honnen
    Mar 22 at 19:03











  • From Evan Lenz copyright notice: Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:... keep, reproduce the notice and don't make claims about Evan endorsement

    – Alejandro
    Mar 22 at 19:22

















  • I appreciate the answer but with my requirements it's complicated for me to use code from a 3rd party.

    – Joshua Hedges
    Mar 22 at 18:11






  • 1





    Using code from an answer of StackOverflow would not be using code from a 3rd party? Anyway, try to find out whether the processor/enviroment has any extension function to solve that or easily allows you to write one that performs the serialization.

    – Martin Honnen
    Mar 22 at 19:03











  • From Evan Lenz copyright notice: Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:... keep, reproduce the notice and don't make claims about Evan endorsement

    – Alejandro
    Mar 22 at 19:22
















I appreciate the answer but with my requirements it's complicated for me to use code from a 3rd party.

– Joshua Hedges
Mar 22 at 18:11





I appreciate the answer but with my requirements it's complicated for me to use code from a 3rd party.

– Joshua Hedges
Mar 22 at 18:11




1




1





Using code from an answer of StackOverflow would not be using code from a 3rd party? Anyway, try to find out whether the processor/enviroment has any extension function to solve that or easily allows you to write one that performs the serialization.

– Martin Honnen
Mar 22 at 19:03





Using code from an answer of StackOverflow would not be using code from a 3rd party? Anyway, try to find out whether the processor/enviroment has any extension function to solve that or easily allows you to write one that performs the serialization.

– Martin Honnen
Mar 22 at 19:03













From Evan Lenz copyright notice: Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:... keep, reproduce the notice and don't make claims about Evan endorsement

– Alejandro
Mar 22 at 19:22





From Evan Lenz copyright notice: Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:... keep, reproduce the notice and don't make claims about Evan endorsement

– Alejandro
Mar 22 at 19:22



















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55303127%2fhow-do-i-serialize-output-from-a-node-set-in-xslt-1-0%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현