getting the correct child nodes under the correct branch nodes

I am using xslt to transform the below XML file into a hierarchy

<?xml version="1.0" encoding="iso-8859-1" ?>
<TABLE>
<LABS>
<STUDY_ID_OR_NUMBER> 01234 </STUDY_ID_OR_NUMBER>
<SITE_ID_OR_NUMBER> 01 </SITE_ID_OR_NUMBER>
<INVESTIGATOR_ID_OR_NUMBER> 01 </INVESTIGATOR_ID_OR_NUMBER >
<INVESTIGATOR_NAME > Dr. Jones </INVESTIGATOR_NAME>
<SCREEN_ID_OR_NUMBER> 100 </SCREEN_ID_OR_NUMBER>
<VISIT_ID_OR_NUMBER> CYCLE1/DAY1 </VISIT_ID_OR_NUMBER>
</LABS>
<LABS>
<STUDY_ID_OR_NUMBER> 01234 </STUDY_ID_OR_NUMBER>
<SITE_ID_OR_NUMBER> 01 </SITE_ID_OR_NUMBER>
<INVESTIGATOR_ID_OR_NUMBER> 01 </INVESTIGATOR_ID_OR_NUMBER >
<INVESTIGATOR_NAME > Dr. Jones </INVESTIGATOR_NAME>
<SCREEN_ID_OR_NUMBER> 200 </SCREEN_ID_OR_NUMBER>
<VISIT_ID_OR_NUMBER> CYCLE1/DAY1 </VISIT_ID_OR_NUMBER>
</LABS>
<LABS>
<STUDY_ID_OR_NUMBER> 01234 </STUDY_ID_OR_NUMBER>
<SITE_ID_OR_NUMBER> 02 </SITE_ID_OR_NUMBER>
<INVESTIGATOR_ID_OR_NUMBER> 02 </INVESTIGATOR_ID_OR_NUMBER >
<INVESTIGATOR_NAME > Dr. Smith </INVESTIGATOR_NAME>
<SCREEN_ID_OR_NUMBER> 100 </SCREEN_ID_OR_NUMBER>
<VISIT_ID_OR_NUMBER> CYCLE1/DAY2 </VISIT_ID_OR_NUMBER>
</LABS>
<LABS>
<STUDY_ID_OR_NUMBER> 01234 </STUDY_ID_OR_NUMBER>
<SITE_ID_OR_NUMBER> 02 </SITE_ID_OR_NUMBER>
<INVESTIGATOR_ID_OR_NUMBER> 02 </INVESTIGATOR_ID_OR_NUMBER >
<INVESTIGATOR_NAME > Dr. Smith </INVESTIGATOR_NAME>
<SCREEN_ID_OR_NUMBER> 200 </SCREEN_ID_OR_NUMBER>
<VISIT_ID_OR_NUMBER> CYCLE2/DAY1 </VISIT_ID_OR_NUMBER>
</LABS>
</TABLE>

And I want to transform it using this xslt:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xsi="http://www.w3.org/2000/10/XMLSchema-instance">
<xsl:output method = "xml" omit-xml-declaration="no" indent = 'yes'/>

<xsl:template match="/">

<GTP xmlns:xsi="http://www.w3.org/2000/10/XMLSchema-instance" xsi:noNamespaceSchemaLocation="CDISC.xsd">

<xsl:element name="Study">

<xsl:element name="File_Creation_Date_and_Time">
<xsl:text>Need to generate time stamp</xsl:text>
</xsl:element>

<xsl:element name="Model_Version">
<xsl:text>1-0-0</xsl:text>
</xsl:element>

<xsl:element name="Transmission_Source_ID">
<xsl:text>MDS</xsl:text>
</xsl:element>

<xsl:element name="Transmission_Source_Name">
<xsl:text>MDS</xsl:text>
</xsl:element>

<xsl:element name="Study_Name">
<xsl:text> STUDY</xsl:text>
</xsl:element>


<xsl:element name="Transmission_Type">
<xsl:text>I</xsl:text>
</xsl:element>

<xsl:apply-templates select="TABLE"/>

</xsl:element>

</GTP>

</xsl:template>

<xsl:template match="TABLE">

<xsl:for-each select="LABS">
<xsl:variable name="Investigator">
<xsl:value-of select="INVESTIGATOR_NAME/text()"/>
</xsl:variable>
<xsl:if test="not(preceding::INVESTIGATOR_NAME[contains(text(),$Investigator)])">
<Investigator>
<Investigator_ID_or_Number>
<xsl:value-of select="INVESTIGATOR_ID_OR_NUMBER"/>
</Investigator_ID_or_Number>
<INVESTIGATOR_NAME>
<xsl:value-of select="INVESTIGATOR_NAME"/>
</INVESTIGATOR_NAME>
<xsl:apply-templates select="//LABS[INVESTIGATOR_NAME=$Investigator]" mode = "Screen_ID_or_Number" />
</Investigator>
</xsl:if>
</xsl:for-each>

</xsl:template>

<xsl:template match="LABS" mode = "Screen_ID_or_Number">

<xsl:variable name="Screen_ID_or_Number">
<xsl:value-of select="SCREEN_ID_OR_NUMBER/text()"/>
</xsl:variable>
<xsl:if test="not(preceding::SCREEN_ID_OR_NUMBER[contains(text(),$Screen_ID_or_Number)])">
<Subject>
<Screen_ID_or_Number>
<xsl:value-of select="SCREEN_ID_OR_NUMBER"/>
</Screen_ID_or_Number>

<xsl:apply-templates select="//LABS[SCREEN_ID_OR_NUMBER=$Screen_ID_or_Number]" mode = "VISIT" />
</Subject>
</xsl:if>

</xsl:template>

<xsl:template match="LABS" mode = "VISIT">
<xsl:variable name="Visit">
<xsl:value-of select="VISIT_ID_OR_NUMBER/text()"/>
</xsl:variable>
<xsl:if test="not(preceding::VISIT_ID_OR_NUMBER[contains(text(),$Visit)])">
<Visit>
<Visit>
<xsl:value-of select="VISIT_ID_OR_NUMBER"/>
</Visit>

</Visit>
</xsl:if>
</xsl:template>

</xsl:stylesheet>

I am not getting the correct child nodes under the correct branch nodes. The output looks like this:
<?xml version="1.0" encoding="UTF-8" ?>
- <GTP xmlns:xsi="http://www.w3.org/2000/10/XMLSchema-instance" xsi:noNamespaceSchemaLocation="CDISC.xsd">
- <Study>
<File_Creation_Date_and_Time>Need to generate time stamp</File_Creation_Date_and_Time>
<Model_Version>1-0-0</Model_Version>
<Transmission_Source_ID>MDS</Transmission_Source_ID>
<Transmission_Source_Name>MDS</Transmission_Source_Name>
<Study_Name>PFIZER STUDY</Study_Name>
<Transmission_Type>I</Transmission_Type>
- <Investigator>
<Investigator_ID_or_Number>01</Investigator_ID_or_Number>
<INVESTIGATOR_NAME>Dr. Jones</INVESTIGATOR_NAME>
- <Subject>
<Screen_ID_or_Number>100</Screen_ID_or_Number>
- <Visit>
<Visit>CYCLE1/DAY1</Visit>
</Visit>
- <Visit>
<Visit>CYCLE1/DAY2</Visit>
</Visit>
</Subject>
- <Subject>
<Screen_ID_or_Number>200</Screen_ID_or_Number>
- <Visit>
<Visit>CYCLE2/DAY1</Visit>
</Visit>
</Subject>
</Investigator>
- <Investigator>
<Investigator_ID_or_Number>02</Investigator_ID_or_Number>
<INVESTIGATOR_NAME>Dr. Smith</INVESTIGATOR_NAME>
</Investigator>
</Study>
</GTP>

is it possible in the <xsl:value-of select=""> statement to only select nodes based on other leaves in the branch?

TIA
[7366 byte] By [jch] at [2007-11-19 3:55:43]
# 1 Re: getting the correct child nodes under the correct branch nodes
ok, I am trying keys but I have the same problem. Is there anyway you can specify two conditions in the same select statement

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xsi="http://www.w3.org/2000/10/XMLSchema-instance">
<xsl:output method = "xml" omit-xml-declaration="no" indent = 'yes'/>

<xsl:key name="INVNAME" match="LABS" use="INVESTIGATOR_NAME" />
<xsl:key name="SCRNID" match="LABS" use="SCREEN_ID_OR_NUMBER" />

<xsl:template match="/">

<GTP xmlns:xsi="http://www.w3.org/2000/10/XMLSchema-instance" xsi:noNamespaceSchemaLocation="CDISC.xsd">

<xsl:element name="Study">

<xsl:element name="File_Creation_Date_and_Time">
<xsl:text>Need to generate time stamp</xsl:text>
</xsl:element>

<xsl:element name="Model_Version">
<xsl:text>1-0-0</xsl:text>
</xsl:element>

<xsl:element name="Transmission_Source_ID">
<xsl:text>MDS</xsl:text>
</xsl:element>

<xsl:element name="Transmission_Source_Name">
<xsl:text>MDS</xsl:text>
</xsl:element>

<xsl:element name="Study_Name">
<xsl:text> STUDY</xsl:text>
</xsl:element>


<xsl:element name="Transmission_Type">
<xsl:text>I</xsl:text>
</xsl:element>

<xsl:apply-templates select="TABLE"/>

</xsl:element>

</GTP>

</xsl:template>


<xsl:template match="TABLE">
<house_list>
<!-- cycle through the first records in each group -->
<xsl:for-each select="LABS[generate-id() = generate-id(key('INVNAME',
INVESTIGATOR_NAME)[1])]">

<Investigator_Name><xsl:value-of select="INVESTIGATOR_NAME" /></Investigator_Name>
<Investigator>
<!-- cycle through each of the INVNAME in the group -->
<xsl:for-each select="key('INVNAME', INVESTIGATOR_NAME)">
<Screen_ID_or_Number>
<xsl:value-of select="SCREEN_ID_OR_NUMBER" />
</Screen_ID_or_Number>
<Visit>
<!-- cycle through each of the SCREENING IDS in the group -->
<xsl:for-each select="key('SCRNID', SCREEN_ID_OR_NUMBER)">
<Visit_ID_or_Number>
<xsl:value-of select="VISIT_ID_OR_NUMBER" />
</Visit_ID_or_Number>
</xsl:for-each>

</Visit>

</xsl:for-each>
</Investigator>

</xsl:for-each>
</house_list>
</xsl:template>

</xsl:stylesheet>
jch at 2007-11-10 3:27:44 >
# 2 Re: getting the correct child nodes under the correct branch nodes
WOW you posted a lot of code, and code is nice. But you say almost nothing about what you want to do, which makes the code rather meaning less to me. I'am not going to spend an half an hour or more reading your code, trying to figure out what you are trying to do, just because you are too lazy say anything about it.

Which makes it difficult for me to answer in anything but the most generic terms,

Yes its possible to make selections based on other elements in the document.
Using an expression like nodetype[exp] in the exp you can check elements along any xpath axis.
And yes its possible to make selections based on multiple conditions using and nodetype[exp1 and exp2] or multiple conditions nodetype[exp1][exp2]

Oh and for the love of god please use code tags on your code. It would have made your posting much much more readable.
khp at 2007-11-10 3:28:47 >