Solved

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

Posted on 2000-04-24
2
263 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
  • 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

How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Getting attribute Values using xslt 4 54
Trouble parsing soap xml result 3 57
XML to Excel using XSL - formatting 3 37
MS Access XML Export Query Setup Multiple Tag Values 15 40
The Client Need Led Us to RSS I recently had an investment company ask me how they might notify their constituents about their newsworthy publications.  Probably you would think "Facebook" or "Twitter" but this is an interesting client.  Their cons…
The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

856 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