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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to display value of an attribute based on another attribute's valu

Status
Not open for further replies.

srtwentyde

Technical User
Sep 29, 2002
1
US
I am a newbie, and I just looked at the FAQ and search turned up too many irrelevant things. I want to display the value of name in data item when I'm matching another element:

<TABLE name=&quot;table1&quot;>
<ITEM id=&quot;105&quot; name=&quot;col1&quot;/>
<ITEM id=&quot;106&quot; name=&quot;col2&quot;/>
<IDX NAME=&quot;IDX1&quot;>
<D_ID col_id=&quot;105&quot;/>
<D_ID col_id=&quot;106&quot;/>
</IDX>
</TABLE>

I want to print plaintext output in SQL so it looks like:

CREATE UNIQUE INDEX IDX1 on table1 (col1, col2);

My XSL is something like:


<xsl:template-match select=&quot;IDX&quot;>
CREATE UNIQUE INDEX <xsl:value-of select=&quot;@NAME&quot;/> on <xsl:value-of select=&quot;TABLE[@name]&quot;/> (<xsl:apply-templates select=&quot;D_ID&quot;/>
</xsl:template>

<xsl:template-match select=&quot;D_ID&quot;>
<xsl:value-of select=&quot;col_id&quot;/>);
</xsl:template>

This last template can only print 105, 106); so my output looks like: CREATE UNIQUE INDEX IDX1 on table1 (105, 106);

while I was really looking to print:

CREATE UNIQUE INDEX IDX1 on table1 (col1, col2);

How do I print the 'name' in ITEM rather than the 'col_id' in the &quot;D_ID&quot; template?

Thanks for your time.

srtwentyde



 
give this a try.

Code:
<xsl:template match=&quot;IDX&quot;>
	CREATE UNIQUE INDEX <xsl:value-of select=&quot;./@NAME&quot; /> on 
	<xsl:value-of select=&quot;../TABLE[@name]&quot;/> (
	<xsl:apply-templates select=&quot;../ITEM&quot;/> );
</xsl:template>

<xsl:template match=&quot;ITEM&quot;>
	<xsl:variable name=&quot;ITEMCnt&quot;>
		<xsl:value-of select=&quot;count(//ITEM)&quot; />
	</xsl:variable>
	<xsl:value-of select=&quot;@name&quot; />
	<xsl:if test=&quot;position() != $ITEMCnt&quot;>
		<xsl:text>, </xsl:text>
	</xsl:if>
</xsl:template>[code]

instead of doing a template match on &quot;D_ID&quot;, go back to the ITEM nodes on the document root.  if it's necessary to call the &quot;D_ID&quot; template for other reasons, you can still call the &quot;ITEM&quot; template from inside &quot;D_ID&quot;.  just make sure you're recursing through the axis correctly. &quot;Until you have the courage to lose sight of the shore, you will not know the terror of being forever lost at sea.&quot; - a very wise man
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top