Note that there are some explanatory texts on larger screens.

plurals
  1. POXSLT If Select Contains "Value"
    primarykey
    data
    text
    <p>I would like to write out 4 questions whether they exist or not.So far my approach has been to select="//NTE_NotesAndCommentsSegment_2/NTE_3_Comment" which retrieves all 3 comments. But I am having trouble with</p> <ol> <li><p>Selecting <code>NTE_3_Comment</code> where it contains <em>"Question 1"</em>(String Value)</p></li> <li><p>Writing out <em>Question 4</em> when the question does not exist.</p></li> <li><p>I also need to output the correct number for the <code>SETID</code>.</p></li> </ol> <p>Note: The question does not actually have the number in it. I am using the ID to sort the output.</p> <p>Input XML:</p> <pre><code>&lt;NTE_NotesAndCommentsSegment_2&gt; &lt;NTE_1_SetIdNotesAndComments&gt;1&lt;/NTE_1_SetIdNotesAndComments&gt; &lt;NTE_2_SourceOfComment&gt;&lt;/NTE_2_SourceOfComment&gt; &lt;NTE_3_Comment&gt;Question 1 ? Answer 1&lt;/NTE_3_Comment&gt; &lt;/NTE_NotesAndCommentsSegment_2&gt; &lt;NTE_NotesAndCommentsSegment_2&gt; &lt;NTE_1_SetIdNotesAndComments&gt;1&lt;/NTE_1_SetIdNotesAndComments&gt; &lt;NTE_2_SourceOfComment&gt;&lt;/NTE_2_SourceOfComment&gt; &lt;NTE_3_Comment&gt;Question 2 ? Answer 2&lt;/NTE_3_Comment&gt; &lt;/NTE_NotesAndCommentsSegment_2&gt; &lt;NTE_NotesAndCommentsSegment_2&gt; &lt;NTE_1_SetIdNotesAndComments&gt;1&lt;/NTE_1_SetIdNotesAndComments&gt; &lt;NTE_2_SourceOfComment&gt;&lt;/NTE_2_SourceOfComment&gt; &lt;NTE_3_Comment&gt;Question 3? Answer 3&lt;/NTE_3_Comment&gt; &lt;/NTE_NotesAndCommentsSegment_2&gt; </code></pre> <p>Expected Output XML:</p> <pre><code>&lt;NTE_NotesAndCommentsSegment_2&gt; &lt;NTE_1_SetIdNotesAndComments&gt;1&lt;/NTE_1_SetIdNotesAndComments&gt; &lt;NTE_2_SourceOfComment&gt;&lt;/NTE_2_SourceOfComment&gt; &lt;NTE_3_Comment&gt;Question 1 ? Answer 1&lt;/NTE_3_Comment&gt; &lt;/NTE_NotesAndCommentsSegment_2&gt; &lt;NTE_NotesAndCommentsSegment_2&gt; &lt;NTE_1_SetIdNotesAndComments&gt;2&lt;/NTE_1_SetIdNotesAndComments&gt; &lt;NTE_2_SourceOfComment&gt;&lt;/NTE_2_SourceOfComment&gt; &lt;NTE_3_Comment&gt;Question 2 ? Answer 2&lt;/NTE_3_Comment&gt; &lt;/NTE_NotesAndCommentsSegment_2&gt; &lt;NTE_NotesAndCommentsSegment_2&gt; &lt;NTE_1_SetIdNotesAndComments&gt;3&lt;/NTE_1_SetIdNotesAndComments&gt; &lt;NTE_2_SourceOfComment&gt;&lt;/NTE_2_SourceOfComment&gt; &lt;NTE_3_Comment&gt;Question 3 ? Answer 3&lt;/NTE_3_Comment&gt; &lt;/NTE_NotesAndCommentsSegment_2&gt; &lt;NTE_NotesAndCommentsSegment_2&gt; &lt;NTE_1_SetIdNotesAndComments&gt;4&lt;/NTE_1_SetIdNotesAndComments&gt; &lt;NTE_2_SourceOfComment&gt;&lt;/NTE_2_SourceOfComment&gt; &lt;NTE_3_Comment&gt;Question 4 ? *Blank* &lt;/NTE_3_Comment&gt; &lt;/NTE_NotesAndCommentsSegment_2&gt; </code></pre> <p>I am looking for suggestions that can help me change my approach to this solution. Thanks in Advance.</p> <p>Solution: Thanks to @O.R.Mapper suggestion. All four questions will be written out every time whether the question exist or not. The answers will display blank if the question does not exist in the source. </p> <pre><code> &lt;NTE_NotesAndCommentsSegment_2&gt; &lt;NTE_1_SetIdNotesAndComments&gt;1&lt;/NTE_1_SetIdNotesAndComments&gt; &lt;NTE_3_Comment&gt;Question 1 ?&lt;xsl:value-of select="substring-after(//NTE_NotesAndCommentsSegment_2/NTE_3_Comment[starts-with(text(),'Question 1')],'?')"/&gt; &lt;/NTE_3_Comment&gt; &lt;/NTE_NotesAndCommentsSegment_2&gt; &lt;NTE_NotesAndCommentsSegment_2&gt; &lt;NTE_1_SetIdNotesAndComments&gt;2&lt;/NTE_1_SetIdNotesAndComments&gt; &lt;NTE_3_Comment&gt;Question 2 ?&lt;xsl:value-of select="substring-after(//NTE_NotesAndCommentsSegment_2/NTE_3_Comment[starts-with(text(),'Question 2')],'?')"/&gt; &lt;/NTE_3_Comment&gt; &lt;/NTE_NotesAndCommentsSegment_2&gt; &lt;NTE_NotesAndCommentsSegment_2&gt; &lt;NTE_1_SetIdNotesAndComments&gt;3&lt;/NTE_1_SetIdNotesAndComments&gt; &lt;NTE_3_Comment&gt;Question 3 ?&lt;xsl:value-of select="substring-after(//NTE_NotesAndCommentsSegment_2/NTE_3_Comment[starts-with(text(),'Question 3')],'?')"/&gt; &lt;/NTE_3_Comment&gt; &lt;/NTE_NotesAndCommentsSegment_2&gt; &lt;NTE_NotesAndCommentsSegment_2&gt; &lt;NTE_1_SetIdNotesAndComments&gt;4&lt;/NTE_1_SetIdNotesAndComments&gt; &lt;NTE_3_Comment&gt;Question 4 ? &lt;xsl:value-of select="substring-after(//NTE_NotesAndCommentsSegment_2/NTE_3_Comment[starts-with(text(),'Question 4')],'?')"/&gt; &lt;/NTE_3_Comment&gt; &lt;/NTE_NotesAndCommentsSegment_2&gt; </code></pre>
    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.
    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