Solved

what meaning of the "<xsl:value-of select="../product[index() $gt$ context()!index()][0]"/>"

Posted on 2000-04-24
2
272 Views
Last Modified: 2006-11-17
<xsl:for-each select="products/product">
<TABLE BORDER="1">
          <xsl:for-each select="products/product">
            <xsl:if expr="(childNumber(this) % 3) == 1">
              <TR>
                <TD><xsl:value-of /></TD>
                <TD><xsl:value-of select="../product[index() $gt$ context()!index()][0]"/></TD>
                <TD><xsl:value-of select="../product[index() $gt$ context()!index()][1]"/></TD>
              </TR>
            </xsl:if>
          </xsl:for-each>
        </TABLE>
</xsl:for-each>

and how to use the attribute to do table like about , and please give the example.


<!--<?xml version="1.0"?>-->
<?xml:stylesheet type="text/xsl" href="auction.asp" ?>
<xml xmlns:s="uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882" xmlns:dt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882" xmlns:rs="urn:schemas-microsoft-com:rowset" xmlns:z="#RowsetSchema">
<s:Schema id="RowsetSchema">
<s:ElementType name="categories" content="eltOnly">
<s:attribute type='typename'/>
<s:attribute type='numbers'/>

<s:extends type="rs:rowbase" />
</s:ElementType>
<s:AttributeType name='typename' rs:number='1' rs:nullable='true' rs:write='true'>
<s:datatype dt:type='string' dt:maxLength='50'/>
  </s:AttributeType>
<s:AttributeType name='numbers' rs:number='2' rs:nullable='true' rs:write='true'>
<s:datatype dt:type='string' dt:maxLength='50'/>
  </s:AttributeType>

</s:Schema>
<rs:data>
<z:categories typename='Textiles and Apparel' numbers='117' />
<z:categories typename='Other' numbers='119' />
<z:categories typename='Chemicals' numbers='101' />
<z:categories typename='Computer' numbers='102' />
<z:categories typename='Construction' numbers='103' />
<z:categories typename='Consumer Goods' numbers='104' />
<z:categories typename='Electronics' numbers='105' />
<z:categories typename='Energy, Mining and Minerals' numbers='106' />
<z:categories typename='Entertainment and Media Production' numbers='107' />
<z:categories typename='Environment' numbers='108' />
<z:categories typename='Food and Beverage' numbers='109' />
<z:categories typename='Forestry and Agriculture' numbers='110' />
<z:categories typename='Manufacturing and Processing' numbers='112' />
<z:categories typename='Packaging' numbers='113' />
<z:categories typename='Printing and Publishing' numbers='114' />
<z:categories typename='Science and Medicine' numbers='115' />
<z:categories typename='Industrial Supplies' numbers='111' />
<z:categories typename='Business and Office' numbers='100' />
<z:categories typename='Transportation' numbers='118' />
<z:categories typename='Telecommunication' numbers='116' />

</rs:data>
</xml>

this id my xml file , and i would like to draw the table with 4 column to put the attribute "typename" so how to solve this problem ????
0
Comment
Question by:kwq5421
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
2 Comments
 

Accepted Solution

by:
PDurgaPrasad earned 200 total points
ID: 2750309
Hi KWG,

In your question, you have given

<xsl:for-each select="products/product">

two times before and after the <TABLE BORDER="1">  tag, but it should be only once.

And coming to

<xsl:value-of select="../product[index() $gt$ context()!index()][0]"/>

This means that it returns the subelement of product[x][0], where x may be 0 or 1 depending on the condition satisfied in  

index() $gt$ context()!index().

here,

index() returns the index number of the node within the parent.

context() retrieve nodes relative to the node at which the query starts.

For example,

context(0) is the root of the subtree upon which transformNode was called. context(1) is the context of the first context-switching XSL element in the style sheet (specified with the select attribute)

Following is a best sample that uses xsl:for-each, xsl:value-of tags by using context() that displays the individual class details by giving its member details i.e. teachers and students .

<XML id="data">
  <data>
    <classes mingrade="B">
      <class nid="1">
        <teacher tid="1"/>
        <student sid="1"/>
        <student sid="2"/>
        <student sid="3"/>
      </class>
      <class nid="2">
        <teacher tid="1"/>
        <teacher tid="2"/>
        <student sid="4"/>
        <student sid="2"/>
        <student sid="3"/>
      </class>
    </classes>
       
    <teachers>
      <teacher tid="1">Teresa Atkinson</teacher>
      <teacher tid="2">Steve DeBroux</teacher>
    </teachers>
   
    <students>
      <student id="1">
         <name>Kathie Flood</name>
         <grade>A</grade>
      </student>
      <student sid="2">
        <name>William Herlan</name>
        <grade>B</grade>
      </student>
      <student sid="3">
        <name>Paul West</name>
        <grade>D</grade>
      </student>
      <student sid="4">
        <name>Wendy Wheeler</name>
        <grade>C</grade>
     </student>
    </students>
  </data>
</XML>

<!--The XSL style sheet-->
<XML id="style">
  <xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl">
    <xsl:template match="/">
      <xsl:for-each select="data/classes">
        <xsl:for-each select="class">
          <DIV>Class <xsl:value-of select="@nid"/></DIV>
          <HR/>
          <P>Teacher(s)
            <xsl:for-each select="teacher">
              <DIV>
                <xsl:value-of select="context(0)/data/teachers/teacher[(@tid = context(-1)/@tid)]"/>
              </DIV>
            </xsl:for-each>
          </P>
          <BR/>
          <P>Student(s)
            <xsl:for-each select="student">
              <DIV>
                <xsl:value-of select="context(0)/data/students/student[(@sid =
                  context(-1)/@sid) and (grade $le$ context(-3)/@mingrade)]/name"/>
              </DIV>
            </xsl:for-each>
          </P>
          <HR noshade="true" color="red"/>
        </xsl:for-each>
      </xsl:for-each>
    </xsl:template>
  </xsl:stylesheet>
</XML>

Hope this is useful to you.

Prasad.
0
 

Expert Comment

by:PDurgaPrasad
ID: 2750353
I think you used ADO Recordset object's 'Save' mathod to get the XML file given by u that contains the XML Schema and XML data.

Prasad.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
Many times as a report developer I've been asked to display normalized data such as three rows with values Jack, Joe, and Bob as a single comma-separated string such as 'Jack, Joe, Bob', and vice versa.  Here's how to do it. 
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question