0

I am trying to pull through a specific question text based on the id tag of the question. I am using pure XPath as a condition but when I have added this condition it is not pulling through the correct question and keeps referring to the top question text rather than the one I put in my condition.

The XML is as per the below:

<a:NeedsAndPriorities>
  <a:Sub-Categories>
    <a:Sub-Category Id="55" Display="xcat">
      <a:Questions>
        <a:Question Id="340" Display="xcat/Shaun test 1">
          <a:QuestionText xmlns:q151="http://www.w3.org/2001/XMLSchema" p9:type="q151:string" xmlns:p9="http://www.w3.org/2001/XMLSchema-instance">Shaun test 1</a:QuestionText>
          <a:PossibleAnswers />
        </a:Question>
      </a:Questions>
      <a:CategoryName xmlns:q152="http://www.w3.org/2001/XMLSchema" p7:type="q152:string" xmlns:p7="http://www.w3.org/2001/XMLSchema-instance">xcat</a:CategoryName>
    </a:Sub-Category>
    <a:Sub-Category Id="160" Display="New">
      <a:Questions>
        <a:Question Id="4" Display="New/Test Mortgage Question">
          <a:QuestionText xmlns:q153="http://www.w3.org/2001/XMLSchema" p9:type="q153:string" xmlns:p9="http://www.w3.org/2001/XMLSchema-instance">Test Mortgage Question</a:QuestionText>
          <a:PossibleAnswers>
            <a:PosibleAnswer>
              <a:Answer>Test mortgage Answer-1</a:Answer>
            </a:PosibleAnswer>

My path is

//NeedsAndPriorities/Sub-Categories/Sub-Category/Questions/Question/QuestionText

My condition is

//NeedsAndPriorities/Sub-Categories/Sub-Category/Questions/Question[@Id = '4']

again this is using pure xpath and it is not nested in the xml. Whenever i run the condition it is pulling through the question text for "340" 'Shaun test 1'.

Any ideas where i am going wrong?

kjhughes
  • 106,133
  • 27
  • 181
  • 240
FreshX
  • 57
  • 2
  • 10
  • 2
    You're failing to take namespaces into account. Note that your XML also is not namespace-well-formed because it uses undeclared namespace prefixes. – kjhughes Nov 22 '16 at 18:15
  • So will the condition not work for what i want to do then? – FreshX Nov 23 '16 at 08:33
  • Forgot to mention the a: is not taken into account on the generated documents with the conditions – FreshX Nov 23 '16 at 08:58
  • Your condition (XPath) will work as expected only if it accounts for any namespaces used in the XML (or skirts namespaces via tests against `local-name()`). – kjhughes Nov 23 '16 at 13:43

0 Answers0