Solved

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

Posted on 2000-04-24
2
256 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
Comment Utility
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
Comment Utility
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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

The Problem How to write an Xquery that works like a SQL outer join, providing placeholders for absent data on the outer side?  I give a bit more background at the end. The situation expressed as relational data Let’s work through this.  I’ve …
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, …
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

763 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now