Note that there are some explanatory texts on larger screens.

plurals
  1. POXSLT delete inside <g> element of an
    primarykey
    data
    text
    <p>I have some svg code that looks like this:</p> <pre><code>&lt;?xml version="1.0"?&gt; &lt;!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"&gt; &lt;svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"&gt; &lt;g id="outer"&gt; &lt;g id="inner-1"&gt; &lt;defs&gt; &lt;rect/&gt; &lt;/defs&gt; &lt;clipPath&gt;&lt;/clipPath&gt; &lt;polygon/&gt; &lt;/g&gt; &lt;text&gt;Some&lt;/text&gt; &lt;text&gt;Text&lt;/text&gt; &lt;g id="inner-2"&gt; &lt;defs&gt; &lt;rect/&gt; &lt;/defs&gt; &lt;clipPath&gt;&lt;/clipPath&gt; &lt;polygon/&gt; &lt;/g&gt; &lt;text&gt;Some&lt;/text&gt; &lt;text&gt;Text&lt;/text&gt; &lt;text&gt;Some&lt;/text&gt; &lt;text&gt;Text&lt;/text&gt; &lt;g id="inner-3"&gt; &lt;defs&gt; &lt;rect/&gt; &lt;/defs&gt; &lt;clipPath&gt;&lt;/clipPath&gt; &lt;polygon/&gt; &lt;/g&gt; &lt;text&gt;Keep this text&lt;/text&gt; &lt;text&gt;Keep this text&lt;/text&gt; &lt;/g&gt; &lt;/svg&gt; </code></pre> <p>How do I delete the 2nd and 3rd occurrence of the inner <code>&lt;g&gt;</code> tags and the <code>&lt;text&gt;</code> tags after the 1st inner <code>&lt;g&gt;</code>, and the <code>&lt;text&gt;</code> tags after the 2nd inner <code>&lt;g&gt;</code> tag. I could have nth many <code>&lt;text&gt;</code> tags after a <code>&lt;g&gt;</code>tag, but I will always "delete" (not selecting by over-riding the identity transformation) the 2nd inner <code>&lt;g&gt;</code> tag and the text that comes before that, and the 3rd inner <code>&lt;g&gt;</code> tag and the text that comes before that. I only want 1st occurrence of the inner'' tag and the <code>&lt;text&gt;</code> tag(s) that follow the 3rd occurrence of the inner '' tag. It should like this:</p> <pre><code>&lt;?xml version="1.0"?&gt; &lt;!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"&gt; &lt;svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"&gt; &lt;g id="outer"&gt; &lt;g id="inner-1"&gt; &lt;defs&gt; &lt;rect/&gt; &lt;/defs&gt; &lt;clipPath&gt;&lt;/clipPath&gt; &lt;polygon/&gt; &lt;/g&gt; &lt;text&gt;Keep this text&lt;/text&gt; &lt;text&gt;Keep this text&lt;/text&gt; &lt;/g&gt; &lt;/svg&gt; </code></pre> <p>Here's what I came up with:</p> <pre><code> &lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"&gt; &lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:svg="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns="http://www.w3.org/2000/svg"&gt; &lt;xsl:template match="node()|@*"&gt; &lt;xsl:copy&gt; &lt;xsl:apply-templates select="node()|@*"/&gt; &lt;/xsl:copy&gt; &lt;/xsl:template&gt; &lt;!-- I don't know how to select preceding text --&gt; &lt;xsl:template match="/svg/g/g[2]"/&gt; &lt;!-- I don't know how to select preceding text --&gt; &lt;xsl:template match="/svg/g/g[3]"/&gt; &lt;/stylesheet&gt; </code></pre> <p>I tried using this code to transform the text elements following the 3rd <code>&lt;g&gt;</code> tag: </p> <pre><code>&lt;xsl:template match="svg:text"&gt; &lt;xsl:choose&gt; &lt;xsl:when test="(following::svg:g[3])[parent::svg:g]"&gt; &lt;xsl:copy-of select="."/&gt; &lt;/xsl:when&gt; &lt;xsl:otherwise/&gt; &lt;/xsl:choose&gt; &lt;/xsl:template&gt; </code></pre> <p>...And that didn't work.</p>
    singulars
    1. This table or related slice is empty.
    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.
    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