Note that there are some explanatory texts on larger screens.

plurals
  1. POMove certain nodes that are sibling of select node into a new parent node
    primarykey
    data
    text
    <p>I did some searching here and found some questions that were related to my problem, but I'm still having trouble...(hope it's ok that I'm adding a new question instead of commenting on an existing one..)</p> <pre><code>&lt;?xml version="1.0"?&gt; &lt;section&gt; &lt;title&gt;Main Section&lt;/title&gt; &lt;para&gt;Here is some text that is a child of a main section.&lt;/para&gt; &lt;para&gt;Some more text.&lt;/para&gt; &lt;para&gt;When a section has subsections, it should not have loose paragraphs before the first sub section. Those loose paras should be placed inside a comment element.&lt;/para&gt; &lt;section&gt; &lt;title&gt;This is my subsection&lt;/title&gt; &lt;para&gt;Text that is inside of the sub-section&lt;/para&gt; &lt;para&gt;And some more sub section text.&lt;/para&gt; &lt;/section&gt; &lt;/section&gt; </code></pre> <p>I want to have the /section/para placed inside a newly created comment node, like so:</p> <pre><code>&lt;?xml version="1.0"?&gt; &lt;section&gt; &lt;title&gt;Main Section&lt;/title&gt; &lt;comment&gt; &lt;para&gt;Here is some text that is a child of a main section.&lt;/para&gt; &lt;para&gt;Some more text.&lt;/para&gt; &lt;para&gt;When a section has subsections, it should not have loose paragraphs before the first sub section. Those loose paras should be placed inside a comment element.&lt;/para&gt; &lt;/comment&gt; &lt;section&gt; &lt;title&gt;This is my subsection&lt;/title&gt; &lt;para&gt;Text that is inside of the sub-section&lt;/para&gt; &lt;para&gt;And some more sub section text.&lt;/para&gt; &lt;/section&gt; &lt;/section&gt; </code></pre> <p>I tried some of the suggestions I found searching stackoverflow, the closest one is <a href="https://stackoverflow.com/questions/3632244/move-certain-child-nodes-down-to-a-new-grandchild-level">here.</a></p> <p>This is the stylesheet I'm using:</p> <pre><code>&lt;?xml version='1.0'?&gt; &lt;xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt; &lt;xsl:output method="xml"/&gt; &lt;xsl:template match="node()|@*" name="identity"&gt; &lt;xsl:copy&gt; &lt;xsl:apply-templates select="node()|@*"/&gt; &lt;/xsl:copy&gt; &lt;/xsl:template&gt; &lt;!-- paras that are children of a section that has direct para children and dircect section children --&gt; &lt;xsl:template match="section[para][section]/para[1]"&gt; &lt;comment&gt; &lt;xsl:apply-templates select="../para" mode="commentPara"/&gt; &lt;/comment&gt; &lt;/xsl:template&gt; &lt;xsl:template match="*" mode="commentPara"&gt; &lt;xsl:call-template name="identity"/&gt; &lt;/xsl:template&gt; &lt;xsl:template match="section[para][section]/para"/&gt; &lt;/xsl:stylesheet&gt; </code></pre> <p>It's outputting this: </p> <pre><code>&lt;?xml version='1.0' ?&gt; &lt;section&gt; &lt;title&gt;Main Section&lt;/title&gt; &lt;section&gt; &lt;title&gt;This is my subsection&lt;/title&gt; &lt;para&gt;Text that is inside of the sub-section&lt;/para&gt; &lt;para&gt;And some more sub section text.&lt;/para&gt; &lt;/section&gt; &lt;/section&gt; </code></pre> <p>simply deleting the paras I want to wrap in a comment tag. I tried going essentially line by line through the stylesheet in the question I linked to...any ideas? thanks, bp</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload