did a search for this and didn’t find an answer, so here goes…
I have some xml similar to the following:
<?xml version="1.0" encoding="utf-8"?>
<footnote ref="1">
<para>Here is some text about some guy who made
<emphasis role="italic">fascinating</emphasis> comment I want to quote
<blockquote> So I went to this place and met this guy....</blockquote>
It seemed more interesting at the time.
</para>
</footnote>
I want to use xslt to change it to a new schema (using new namespace prefix)
<?xml version="1.0" encoding="utf-8"?>
<nns:footnote ref="1">
<nns:fn-para>Here is some text about some guy who made
<nns:emph type="it">fascinating</nns:emph> comment I want to quote:
</nns:fn-para>
<nns:fn-blockquote>
<nns:bq-para>So I went to this place and met this guy....</nns:bq-para>
</nns:fn-blockquote>
<nns:fn-para> It seemed more interesting at the time.</nns:fn-para>
</nns:footnote>
I’ve tried a few things…taking a para that’s a descendant of footnote and looping through the children, but that’s problematic because it isn’t only text nodes in the para, there are also emph tags, and I still don’t know how to place a child node up the tree and over in the result tree…doe that make sense?
EDIT: Small refactor and extended explanation.
This stylesheet:
Output:
Note: Identity rule for overwriting (just for style, but it’s a good pattern). Four direct transformation rules matching
footnote,emphasis,@roleattribute ofemphasisandblockquote. Grouping key matching “inline”para‘s children: the generate id of first preceding “block” element orparaparent. Grouping rule forparaapplying templates to self and “block” elements in"group"mode. Rule matchingparain"group"mode (also namedmakePara): output a paragraph if there is a group with context node generate id as key value. Rule matching any element in"group"mode (it’ll be any “block” element): apply templates to self (“reset” mode) and callmakeParanamed template.