• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 318
  • Last Modified:

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

<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
kwq5421
Asked:
kwq5421
  • 2
1 Solution
 
PDurgaPrasadCommented:
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
 
PDurgaPrasadCommented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now