Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Note Sure If This Can Be Done - Can Someone Confirm?

Status
Not open for further replies.

Wickersty

Programmer
Nov 13, 2002
51
US
Hi all. OK - what I've got is an XML file which I'm simplifying right here, so you can have a frame of reference:

<test>
<narrative id=&quot;1&quot;>Write True or False on the line.</narrative>
<narrative id=&quot;2&quot;>Write the answer using complete sentences.</narrative>
<question narrative_id=&quot;1&quot;>Is a dolphin a mammal?</question>
<question narrative_id=&quot;1&quot;>Is a worm alive?</question>
<question narrative_id=&quot;2&quot;>Why does heat rise? Be thorough.</question>
</test>


OK - here's what I'm having problems accomplishing... using an XSLT, I want to parse through the <question> tags and FIRST examine the narrative_id attribute. THEN, having identified the narrative_id attribute, I want to output the text within the <narrative> whose &quot;id&quot; attribute is the same as the &quot;narrative_id&quot; attribute in the <question> I just evaluated. THEN, having outputted that narrative, I want to finish by outputting the text in the <question> tag.

I've been able to output the text with each instance of <question>, AND I've been able to identify the &quot;narrative_id&quot; attribute of each instance of question, but I'm having trouble being able to fetch the value of the correct <narrative> when I need it.

Is this possible using XSLT? Can anyone offer some advice?

Thank you much,

Jeff
 
OK - I've figured out a way for the XSLT to do what I want it to do - anyone that's interested, read on. Also, any of you more knowledgable folk that see a flaw in what I've done, or know of a better way, your comments are welcome.

Here it is:

<xsl:variable name=&quot;the_ID&quot;>
<xsl:value-of select=&quot;@narrative_ID&quot; />
</xsl:variable>
<xsl:for-each select=&quot;/test/narrative&quot;>
<xsl:if test=&quot;@ID=$the_ID&quot;>
<xsl:value-of select=&quot;text&quot; />
</xsl:if>
</xsl:for-each>
 
Couldn't you just do something like this:

Code:
<xsl:template match=&quot;question&quot;>
  <xsl:value-of select=&quot;../narrative[@id=current()/@narrative_id]&quot; />
  <xsl:value-of select=&quot;.&quot; />
</xsl:template>

Perhaps I'm missing something here, but this would seem to be a simpler way.

-Rob
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top