Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 16th, 2007, 08:22 PM
Registered User
 
Join Date: May 2007
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default A beginner's question

I have this xml:

<product>
<quantity>2</quantity>
<Detail>
<Date>20010503</Date>
<Value>2350.00</Value>
<City>New York</City>
</Detail>
<Detail>
<Date>20010502</Date>
<Value>1000.00</Value>
<City>London</City>
</Detail>
<product>

in the xsl I do
<xsl:for-each select="product">
.
.
.
( a lot of stuff that doesn't work)
.
.
.</xsl:for-each>

What I need
| Product |
|Quantity=2 |
|Detail | Detail |
|Date 20010503 | Date 20010502 |
|Value 2350.00 |Value 1000.00 |
|City New York | City London |


What I need to know at the moment is how I can tell that the second "Date", "Value" and "City" values belong to the second "Detail" block and so on so I can pass it correctly to the external application.

Thanks in advance



 
Old May 17th, 2007, 03:07 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

I'm not sure if your output is literally what you want (text in fixed-width columns) or just an illustration of how the HTML might appear in the browser. Either way, if we ignore the formatting and concentrate on the structure, it's essentially:

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



<tr>
<xsl:for-each select="Detail">
  <td>Date <xsl:value-of select="Date"/>
</xsl:for-each select="Detail">
</tr>

<tr>
<xsl:for-each select="Detail">
  <td>Value <xsl:value-of select="Value"/>
</xsl:for-each select="Detail">
</tr>

</xsl:for-each>

etc.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old May 17th, 2007, 08:49 AM
Registered User
 
Join Date: May 2007
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi, thanks for the answer.

I hope I'm not pushing it, but when I wrote that post I didn't have my actual code with, so I may have simplified, here is the real problem:

Xml to be read:
<head>
.
.
.
<Product>
<Quantity>2</Quantity>
      <List>
           <Detail>
                <Date>20010503</Date>
                <Value>2350.00</Value>
                <City>Osasco</CidadeCartorio>
            </Detail>
            <Detail>
                <Date>20010502</Date>
                <Value>1000.00</Value>
                <City>Santos</City>
                </Detail>
        </List>
</Product>
.
.
.
<head>
Xsl at the moment:

<xsl:for-each select="head">
    <Type Name="Product" Id="8">
      <xsl:for-each select="Product">
         <xsl:element name="Block">
         <xsl:attribute name="Index"><xsl:value-of select="position()"/></xsl:attribute>
           <FData FNb="1">
           <xsl:value-of select="Quantity"/>
           </FData>
           <FData FNb="2">
           <xsl:value-of select="List/Detail/Date"/>
           </FData>
           <FData FNb="3">
           <xsl:value-of select="List/Detail/Value"/>
           </FData>
           <FData FNb="4">
               <xsl:value-of select="List/Detail/City"/>
           </FData>
              </xsl:element>
          <xsl:call-template name="create-fnames">
          <xsl:with-param name="typename">Product</xsl:with-param>
              </xsl:call-template>
    </Type>
</xsl:for-each>

It works when I have just one "Detail" block.
the template which FData, blocks, etc are based on is in another file, in this format:

<type name="Product">
<name nb="1">Quantity</name>
<name nb="2">Date</name>
<name nb="3">Value</name>
<name nb="4">City</name>
</type>

The desired output is this one:

<Type Name="Product" Id="8">
<Block Index="1">
  <FData FNb="1">2</FData>
  <FData FNb="2">20010503</FData>
  <FData FNb="3">2350.00</FData>
  <FData FNb="4">Osasco</FData>
</Block>
<Block Index="2">
  <FData FNb="1">2</FData>
  <FData FNb="2">20010502</FData>
  <FData FNb="3">1000.00</FData>
  <FData FNb="4">Santos</FData>
</Block>
<Block Index="1">
  <FName FNb="1">Quantity</FName>
  <FName FNb="2">Date</FName>
  <FName FNb="3">Value</FName>
  <FName FNb="4">City</FName>
</Block>
  <Block Index="2" />
  <FName FNb="1">Quantity</FName>
  <FName FNb="2">Date</FName>
  <FName FNb="3">Value</FName>
  <FName FNb="4">City</FName>
</Block>
</Type>

 
Old May 17th, 2007, 08:56 AM
Registered User
 
Join Date: May 2007
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

The last part could be like this as well.

<Type Name="Product" Id="8">
<Block Index="1">
  <FData FNb="1">2</FData>
  <FData FNb="2">20010503</FData>
  <FData FNb="3">2350.00</FData>
  <FData FNb="4">Osasco</FData>
</Block>
  <FName FNb="1">Quantity</FName>
  <FName FNb="2">Date</FName>
  <FName FNb="3">Value</FName>
  <FName FNb="4">City</FName>
<Block Index="2">
  <FData FNb="1">2</FData>
  <FData FNb="2">20010502</FData>
  <FData FNb="3">1000.00</FData>
  <FData FNb="4">Santos</FData>
</Block>
  <FName FNb="1">Quantity</FName>
  <FName FNb="2">Date</FName>
  <FName FNb="3">Value</FName>
  <FName FNb="4">City</FName>
</Type>

Thanks and again, I'm sorry!


 
Old May 17th, 2007, 09:22 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

That problem seems to have essentially the structure I was assuming, so you should only need to change a few tag names in my code.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old May 17th, 2007, 10:32 AM
Registered User
 
Join Date: May 2007
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Like this?

<xsl:for-each select="efx12">
 <Type Name="Product" Id="8">
    <xsl:for-each select="Product">
    <xsl:element name="Block"> <xsl:attribute name="Index">
               <xsl:value-of select="position()"/>
           </xsl:attribute>
       <xsl:for-each select="Detail"> <FData FNb="1">
            <xsl:value-of select="Quantity"/>
         </FData>
       </xsl:for-each>
       <xsl:for-each select="Detail"> <FData FNb="2">
            <xsl:value-of select="Date"/> </FData>
       </xsl:for-each>
       <xsl:for-each select="Detail">
          <FData FNb="3">
            <xsl:value-of select="Value"/>
          </FData>
      </xsl:for-each>
      <xsl:for-each select="Detail">
         <FData FNb="4">
        <xsl:value-of select="City"/>
         </FData> </xsl:for-each> </xsl:element> </xsl:for-each> <xsl:call-template name="create-fnames">
    <xsl:with-param name="typename">Product</xsl:with-param>
    </xsl:call-template>
    </Type>
</xsl:for-each>

That was the answer, it doesn't show the values of the tags:

<Type Name="Product" Id="8">
  <Block Index="1" />
  <FName FNb="1">Quantity</FName>
  <FName FNb="2">Date</FName>
  <FName FNb="3">Value</FName>
  <FName FNb="4">City</FName>
  <FName FNb="1">Quantity</FName>
  <FName FNb="2">Date</FName>
  <FName FNb="3">Value</FName>
  <FName FNb="4">City</FName>
  </Type>

  Is there a way to increment or detect the block number?






Similar Threads
Thread Thread Starter Forum Replies Last Post
Beginner's Question peytontodd Beginning VB 6 3 March 7th, 2007 11:58 AM
Beginner's question re: WindowsForm DataGrid savoym C# 2 January 19th, 2004 02:51 PM
Help please: another beginner's question savoym C# 1 January 9th, 2004 11:45 AM
Beginner's question savoym C# 2 January 8th, 2004 03:58 PM
Beginner's SQL question pankaj_daga SQL Language 3 November 12th, 2003 07:57 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.