XSLT convert flat single line to hierarchical xml











up vote
0
down vote

favorite












Can you help me to create XSLT 1.0 for converting this xml



<s bold="true" italic="true" color="#FFF000">bold italic and colored text</s>
<s bold="true">bold text</s>
<s italic="true" bold="true">bold italic text</s>


to this html



<p><b><i><span style="color:#FFF000">bold italic and colored text</span></i></b></p>
<p><b>bold text</b></p>
<p><b><i>bold italic text</i></b></p>


Thanks










share|improve this question
























  • That's not XML, it's an XML fragment. -- Anyway, I think you'll find something similar here: stackoverflow.com/questions/28900888/…
    – michael.hor257k
    Nov 21 at 7:45










  • It is ok for single attribute but I have a problem with combining multiple attributes.
    – sonstiq
    Nov 21 at 8:07










  • Which version of XSLT, which XSLT processor can you use?
    – Martin Honnen
    Nov 21 at 8:31










  • My xslt version is 1.0
    – sonstiq
    Nov 21 at 8:40















up vote
0
down vote

favorite












Can you help me to create XSLT 1.0 for converting this xml



<s bold="true" italic="true" color="#FFF000">bold italic and colored text</s>
<s bold="true">bold text</s>
<s italic="true" bold="true">bold italic text</s>


to this html



<p><b><i><span style="color:#FFF000">bold italic and colored text</span></i></b></p>
<p><b>bold text</b></p>
<p><b><i>bold italic text</i></b></p>


Thanks










share|improve this question
























  • That's not XML, it's an XML fragment. -- Anyway, I think you'll find something similar here: stackoverflow.com/questions/28900888/…
    – michael.hor257k
    Nov 21 at 7:45










  • It is ok for single attribute but I have a problem with combining multiple attributes.
    – sonstiq
    Nov 21 at 8:07










  • Which version of XSLT, which XSLT processor can you use?
    – Martin Honnen
    Nov 21 at 8:31










  • My xslt version is 1.0
    – sonstiq
    Nov 21 at 8:40













up vote
0
down vote

favorite









up vote
0
down vote

favorite











Can you help me to create XSLT 1.0 for converting this xml



<s bold="true" italic="true" color="#FFF000">bold italic and colored text</s>
<s bold="true">bold text</s>
<s italic="true" bold="true">bold italic text</s>


to this html



<p><b><i><span style="color:#FFF000">bold italic and colored text</span></i></b></p>
<p><b>bold text</b></p>
<p><b><i>bold italic text</i></b></p>


Thanks










share|improve this question















Can you help me to create XSLT 1.0 for converting this xml



<s bold="true" italic="true" color="#FFF000">bold italic and colored text</s>
<s bold="true">bold text</s>
<s italic="true" bold="true">bold italic text</s>


to this html



<p><b><i><span style="color:#FFF000">bold italic and colored text</span></i></b></p>
<p><b>bold text</b></p>
<p><b><i>bold italic text</i></b></p>


Thanks







xslt






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 21 at 8:40

























asked Nov 21 at 7:25









sonstiq

335




335












  • That's not XML, it's an XML fragment. -- Anyway, I think you'll find something similar here: stackoverflow.com/questions/28900888/…
    – michael.hor257k
    Nov 21 at 7:45










  • It is ok for single attribute but I have a problem with combining multiple attributes.
    – sonstiq
    Nov 21 at 8:07










  • Which version of XSLT, which XSLT processor can you use?
    – Martin Honnen
    Nov 21 at 8:31










  • My xslt version is 1.0
    – sonstiq
    Nov 21 at 8:40


















  • That's not XML, it's an XML fragment. -- Anyway, I think you'll find something similar here: stackoverflow.com/questions/28900888/…
    – michael.hor257k
    Nov 21 at 7:45










  • It is ok for single attribute but I have a problem with combining multiple attributes.
    – sonstiq
    Nov 21 at 8:07










  • Which version of XSLT, which XSLT processor can you use?
    – Martin Honnen
    Nov 21 at 8:31










  • My xslt version is 1.0
    – sonstiq
    Nov 21 at 8:40
















That's not XML, it's an XML fragment. -- Anyway, I think you'll find something similar here: stackoverflow.com/questions/28900888/…
– michael.hor257k
Nov 21 at 7:45




That's not XML, it's an XML fragment. -- Anyway, I think you'll find something similar here: stackoverflow.com/questions/28900888/…
– michael.hor257k
Nov 21 at 7:45












It is ok for single attribute but I have a problem with combining multiple attributes.
– sonstiq
Nov 21 at 8:07




It is ok for single attribute but I have a problem with combining multiple attributes.
– sonstiq
Nov 21 at 8:07












Which version of XSLT, which XSLT processor can you use?
– Martin Honnen
Nov 21 at 8:31




Which version of XSLT, which XSLT processor can you use?
– Martin Honnen
Nov 21 at 8:31












My xslt version is 1.0
– sonstiq
Nov 21 at 8:40




My xslt version is 1.0
– sonstiq
Nov 21 at 8:40












1 Answer
1






active

oldest

votes

















up vote
1
down vote



accepted










Here is an XSLT 3 solution that uses a separate mode to push each attribute through a template to recursively to achieve the nesting:



<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="#all"
version="3.0">

<xsl:mode on-no-match="shallow-copy"/>

<xsl:output method="html" html-version="5"/>

<xsl:template match="s">
<p>
<xsl:apply-templates select="." mode="att"/>
</p>
</xsl:template>

<xsl:template match="s" mode="att">
<xsl:param name="attributes" select="@*"/>
<xsl:apply-templates select="if (head($attributes)) then head($attributes) else node()" mode="att">
<xsl:with-param name="attributes" select="$attributes"/>
</xsl:apply-templates>
</xsl:template>

<xsl:template match="@bold[. = 'true']" mode="att">
<xsl:param name="attributes"/>
<b>
<xsl:apply-templates select=".." mode="att">
<xsl:with-param name="attributes" select="tail($attributes)"/>
</xsl:apply-templates>
</b>
</xsl:template>

<xsl:template match="@italic[. = 'true']" mode="att">
<xsl:param name="attributes"/>
<i>
<xsl:apply-templates select=".." mode="att">
<xsl:with-param name="attributes" select="tail($attributes)"/>
</xsl:apply-templates>
</i>
</xsl:template>

<xsl:template match="@color" mode="att">
<xsl:param name="attributes"/>
<span style="color: {.};">
<xsl:apply-templates select=".." mode="att">
<xsl:with-param name="attributes" select="tail($attributes)"/>
</xsl:apply-templates>
</span>
</xsl:template>

</xsl:stylesheet>


https://xsltfiddle.liberty-development.net/3NzcBuc/0



Its XSLT 1 transliteration would be



<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">

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

<xsl:output method="html" indent="yes" version="5.0" doctype-system="about:legacy-doctype"/>

<xsl:template match="s">
<p>
<xsl:apply-templates select="." mode="att"/>
</p>
</xsl:template>

<xsl:template match="s" mode="att">
<xsl:param name="attributes" select="@*"/>
<xsl:choose>
<xsl:when test="$attributes">
<xsl:apply-templates select="$attributes[1]" mode="att">
<xsl:with-param name="attributes" select="$attributes"/>
</xsl:apply-templates>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>

<xsl:template match="@bold[. = 'true']" mode="att">
<xsl:param name="attributes"/>
<b>
<xsl:apply-templates select=".." mode="att">
<xsl:with-param name="attributes" select="$attributes[position() > 1]"/>
</xsl:apply-templates>
</b>
</xsl:template>

<xsl:template match="@italic[. = 'true']" mode="att">
<xsl:param name="attributes"/>
<i>
<xsl:apply-templates select=".." mode="att">
<xsl:with-param name="attributes" select="$attributes[position() > 1]"/>
</xsl:apply-templates>
</i>
</xsl:template>

<xsl:template match="@color" mode="att">
<xsl:param name="attributes"/>
<span style="color: {.};">
<xsl:apply-templates select=".." mode="att">
<xsl:with-param name="attributes" select="$attributes[position() > 1]"/>
</xsl:apply-templates>
</span>
</xsl:template>

</xsl:stylesheet>


https://xsltfiddle.liberty-development.net/3NzcBuc/1






share|improve this answer





















  • Amazing solution works very fine
    – sonstiq
    Nov 21 at 10:41











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',
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%2f53407097%2fxslt-convert-flat-single-line-to-hierarchical-xml%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








up vote
1
down vote



accepted










Here is an XSLT 3 solution that uses a separate mode to push each attribute through a template to recursively to achieve the nesting:



<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="#all"
version="3.0">

<xsl:mode on-no-match="shallow-copy"/>

<xsl:output method="html" html-version="5"/>

<xsl:template match="s">
<p>
<xsl:apply-templates select="." mode="att"/>
</p>
</xsl:template>

<xsl:template match="s" mode="att">
<xsl:param name="attributes" select="@*"/>
<xsl:apply-templates select="if (head($attributes)) then head($attributes) else node()" mode="att">
<xsl:with-param name="attributes" select="$attributes"/>
</xsl:apply-templates>
</xsl:template>

<xsl:template match="@bold[. = 'true']" mode="att">
<xsl:param name="attributes"/>
<b>
<xsl:apply-templates select=".." mode="att">
<xsl:with-param name="attributes" select="tail($attributes)"/>
</xsl:apply-templates>
</b>
</xsl:template>

<xsl:template match="@italic[. = 'true']" mode="att">
<xsl:param name="attributes"/>
<i>
<xsl:apply-templates select=".." mode="att">
<xsl:with-param name="attributes" select="tail($attributes)"/>
</xsl:apply-templates>
</i>
</xsl:template>

<xsl:template match="@color" mode="att">
<xsl:param name="attributes"/>
<span style="color: {.};">
<xsl:apply-templates select=".." mode="att">
<xsl:with-param name="attributes" select="tail($attributes)"/>
</xsl:apply-templates>
</span>
</xsl:template>

</xsl:stylesheet>


https://xsltfiddle.liberty-development.net/3NzcBuc/0



Its XSLT 1 transliteration would be



<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">

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

<xsl:output method="html" indent="yes" version="5.0" doctype-system="about:legacy-doctype"/>

<xsl:template match="s">
<p>
<xsl:apply-templates select="." mode="att"/>
</p>
</xsl:template>

<xsl:template match="s" mode="att">
<xsl:param name="attributes" select="@*"/>
<xsl:choose>
<xsl:when test="$attributes">
<xsl:apply-templates select="$attributes[1]" mode="att">
<xsl:with-param name="attributes" select="$attributes"/>
</xsl:apply-templates>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>

<xsl:template match="@bold[. = 'true']" mode="att">
<xsl:param name="attributes"/>
<b>
<xsl:apply-templates select=".." mode="att">
<xsl:with-param name="attributes" select="$attributes[position() > 1]"/>
</xsl:apply-templates>
</b>
</xsl:template>

<xsl:template match="@italic[. = 'true']" mode="att">
<xsl:param name="attributes"/>
<i>
<xsl:apply-templates select=".." mode="att">
<xsl:with-param name="attributes" select="$attributes[position() > 1]"/>
</xsl:apply-templates>
</i>
</xsl:template>

<xsl:template match="@color" mode="att">
<xsl:param name="attributes"/>
<span style="color: {.};">
<xsl:apply-templates select=".." mode="att">
<xsl:with-param name="attributes" select="$attributes[position() > 1]"/>
</xsl:apply-templates>
</span>
</xsl:template>

</xsl:stylesheet>


https://xsltfiddle.liberty-development.net/3NzcBuc/1






share|improve this answer





















  • Amazing solution works very fine
    – sonstiq
    Nov 21 at 10:41















up vote
1
down vote



accepted










Here is an XSLT 3 solution that uses a separate mode to push each attribute through a template to recursively to achieve the nesting:



<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="#all"
version="3.0">

<xsl:mode on-no-match="shallow-copy"/>

<xsl:output method="html" html-version="5"/>

<xsl:template match="s">
<p>
<xsl:apply-templates select="." mode="att"/>
</p>
</xsl:template>

<xsl:template match="s" mode="att">
<xsl:param name="attributes" select="@*"/>
<xsl:apply-templates select="if (head($attributes)) then head($attributes) else node()" mode="att">
<xsl:with-param name="attributes" select="$attributes"/>
</xsl:apply-templates>
</xsl:template>

<xsl:template match="@bold[. = 'true']" mode="att">
<xsl:param name="attributes"/>
<b>
<xsl:apply-templates select=".." mode="att">
<xsl:with-param name="attributes" select="tail($attributes)"/>
</xsl:apply-templates>
</b>
</xsl:template>

<xsl:template match="@italic[. = 'true']" mode="att">
<xsl:param name="attributes"/>
<i>
<xsl:apply-templates select=".." mode="att">
<xsl:with-param name="attributes" select="tail($attributes)"/>
</xsl:apply-templates>
</i>
</xsl:template>

<xsl:template match="@color" mode="att">
<xsl:param name="attributes"/>
<span style="color: {.};">
<xsl:apply-templates select=".." mode="att">
<xsl:with-param name="attributes" select="tail($attributes)"/>
</xsl:apply-templates>
</span>
</xsl:template>

</xsl:stylesheet>


https://xsltfiddle.liberty-development.net/3NzcBuc/0



Its XSLT 1 transliteration would be



<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">

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

<xsl:output method="html" indent="yes" version="5.0" doctype-system="about:legacy-doctype"/>

<xsl:template match="s">
<p>
<xsl:apply-templates select="." mode="att"/>
</p>
</xsl:template>

<xsl:template match="s" mode="att">
<xsl:param name="attributes" select="@*"/>
<xsl:choose>
<xsl:when test="$attributes">
<xsl:apply-templates select="$attributes[1]" mode="att">
<xsl:with-param name="attributes" select="$attributes"/>
</xsl:apply-templates>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>

<xsl:template match="@bold[. = 'true']" mode="att">
<xsl:param name="attributes"/>
<b>
<xsl:apply-templates select=".." mode="att">
<xsl:with-param name="attributes" select="$attributes[position() > 1]"/>
</xsl:apply-templates>
</b>
</xsl:template>

<xsl:template match="@italic[. = 'true']" mode="att">
<xsl:param name="attributes"/>
<i>
<xsl:apply-templates select=".." mode="att">
<xsl:with-param name="attributes" select="$attributes[position() > 1]"/>
</xsl:apply-templates>
</i>
</xsl:template>

<xsl:template match="@color" mode="att">
<xsl:param name="attributes"/>
<span style="color: {.};">
<xsl:apply-templates select=".." mode="att">
<xsl:with-param name="attributes" select="$attributes[position() > 1]"/>
</xsl:apply-templates>
</span>
</xsl:template>

</xsl:stylesheet>


https://xsltfiddle.liberty-development.net/3NzcBuc/1






share|improve this answer





















  • Amazing solution works very fine
    – sonstiq
    Nov 21 at 10:41













up vote
1
down vote



accepted







up vote
1
down vote



accepted






Here is an XSLT 3 solution that uses a separate mode to push each attribute through a template to recursively to achieve the nesting:



<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="#all"
version="3.0">

<xsl:mode on-no-match="shallow-copy"/>

<xsl:output method="html" html-version="5"/>

<xsl:template match="s">
<p>
<xsl:apply-templates select="." mode="att"/>
</p>
</xsl:template>

<xsl:template match="s" mode="att">
<xsl:param name="attributes" select="@*"/>
<xsl:apply-templates select="if (head($attributes)) then head($attributes) else node()" mode="att">
<xsl:with-param name="attributes" select="$attributes"/>
</xsl:apply-templates>
</xsl:template>

<xsl:template match="@bold[. = 'true']" mode="att">
<xsl:param name="attributes"/>
<b>
<xsl:apply-templates select=".." mode="att">
<xsl:with-param name="attributes" select="tail($attributes)"/>
</xsl:apply-templates>
</b>
</xsl:template>

<xsl:template match="@italic[. = 'true']" mode="att">
<xsl:param name="attributes"/>
<i>
<xsl:apply-templates select=".." mode="att">
<xsl:with-param name="attributes" select="tail($attributes)"/>
</xsl:apply-templates>
</i>
</xsl:template>

<xsl:template match="@color" mode="att">
<xsl:param name="attributes"/>
<span style="color: {.};">
<xsl:apply-templates select=".." mode="att">
<xsl:with-param name="attributes" select="tail($attributes)"/>
</xsl:apply-templates>
</span>
</xsl:template>

</xsl:stylesheet>


https://xsltfiddle.liberty-development.net/3NzcBuc/0



Its XSLT 1 transliteration would be



<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">

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

<xsl:output method="html" indent="yes" version="5.0" doctype-system="about:legacy-doctype"/>

<xsl:template match="s">
<p>
<xsl:apply-templates select="." mode="att"/>
</p>
</xsl:template>

<xsl:template match="s" mode="att">
<xsl:param name="attributes" select="@*"/>
<xsl:choose>
<xsl:when test="$attributes">
<xsl:apply-templates select="$attributes[1]" mode="att">
<xsl:with-param name="attributes" select="$attributes"/>
</xsl:apply-templates>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>

<xsl:template match="@bold[. = 'true']" mode="att">
<xsl:param name="attributes"/>
<b>
<xsl:apply-templates select=".." mode="att">
<xsl:with-param name="attributes" select="$attributes[position() > 1]"/>
</xsl:apply-templates>
</b>
</xsl:template>

<xsl:template match="@italic[. = 'true']" mode="att">
<xsl:param name="attributes"/>
<i>
<xsl:apply-templates select=".." mode="att">
<xsl:with-param name="attributes" select="$attributes[position() > 1]"/>
</xsl:apply-templates>
</i>
</xsl:template>

<xsl:template match="@color" mode="att">
<xsl:param name="attributes"/>
<span style="color: {.};">
<xsl:apply-templates select=".." mode="att">
<xsl:with-param name="attributes" select="$attributes[position() > 1]"/>
</xsl:apply-templates>
</span>
</xsl:template>

</xsl:stylesheet>


https://xsltfiddle.liberty-development.net/3NzcBuc/1






share|improve this answer












Here is an XSLT 3 solution that uses a separate mode to push each attribute through a template to recursively to achieve the nesting:



<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="#all"
version="3.0">

<xsl:mode on-no-match="shallow-copy"/>

<xsl:output method="html" html-version="5"/>

<xsl:template match="s">
<p>
<xsl:apply-templates select="." mode="att"/>
</p>
</xsl:template>

<xsl:template match="s" mode="att">
<xsl:param name="attributes" select="@*"/>
<xsl:apply-templates select="if (head($attributes)) then head($attributes) else node()" mode="att">
<xsl:with-param name="attributes" select="$attributes"/>
</xsl:apply-templates>
</xsl:template>

<xsl:template match="@bold[. = 'true']" mode="att">
<xsl:param name="attributes"/>
<b>
<xsl:apply-templates select=".." mode="att">
<xsl:with-param name="attributes" select="tail($attributes)"/>
</xsl:apply-templates>
</b>
</xsl:template>

<xsl:template match="@italic[. = 'true']" mode="att">
<xsl:param name="attributes"/>
<i>
<xsl:apply-templates select=".." mode="att">
<xsl:with-param name="attributes" select="tail($attributes)"/>
</xsl:apply-templates>
</i>
</xsl:template>

<xsl:template match="@color" mode="att">
<xsl:param name="attributes"/>
<span style="color: {.};">
<xsl:apply-templates select=".." mode="att">
<xsl:with-param name="attributes" select="tail($attributes)"/>
</xsl:apply-templates>
</span>
</xsl:template>

</xsl:stylesheet>


https://xsltfiddle.liberty-development.net/3NzcBuc/0



Its XSLT 1 transliteration would be



<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">

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

<xsl:output method="html" indent="yes" version="5.0" doctype-system="about:legacy-doctype"/>

<xsl:template match="s">
<p>
<xsl:apply-templates select="." mode="att"/>
</p>
</xsl:template>

<xsl:template match="s" mode="att">
<xsl:param name="attributes" select="@*"/>
<xsl:choose>
<xsl:when test="$attributes">
<xsl:apply-templates select="$attributes[1]" mode="att">
<xsl:with-param name="attributes" select="$attributes"/>
</xsl:apply-templates>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>

<xsl:template match="@bold[. = 'true']" mode="att">
<xsl:param name="attributes"/>
<b>
<xsl:apply-templates select=".." mode="att">
<xsl:with-param name="attributes" select="$attributes[position() > 1]"/>
</xsl:apply-templates>
</b>
</xsl:template>

<xsl:template match="@italic[. = 'true']" mode="att">
<xsl:param name="attributes"/>
<i>
<xsl:apply-templates select=".." mode="att">
<xsl:with-param name="attributes" select="$attributes[position() > 1]"/>
</xsl:apply-templates>
</i>
</xsl:template>

<xsl:template match="@color" mode="att">
<xsl:param name="attributes"/>
<span style="color: {.};">
<xsl:apply-templates select=".." mode="att">
<xsl:with-param name="attributes" select="$attributes[position() > 1]"/>
</xsl:apply-templates>
</span>
</xsl:template>

</xsl:stylesheet>


https://xsltfiddle.liberty-development.net/3NzcBuc/1







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 21 at 8:47









Martin Honnen

110k65876




110k65876












  • Amazing solution works very fine
    – sonstiq
    Nov 21 at 10:41


















  • Amazing solution works very fine
    – sonstiq
    Nov 21 at 10:41
















Amazing solution works very fine
– sonstiq
Nov 21 at 10:41




Amazing solution works very fine
– sonstiq
Nov 21 at 10:41


















 

draft saved


draft discarded



















































 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53407097%2fxslt-convert-flat-single-line-to-hierarchical-xml%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

Berounka

Sphinx de Gizeh

Different font size/position of beamer's navigation symbols template's content depending on regular/plain...