Skip to content
View in the app

A better way to browse. Learn more.

FMForums.com

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

What's wrong with my XSL mark up?

Featured Replies

Dear friends,

 

Could someone check my XSL. I simply want to achieve following XML:

 

<invoices>

<invoice>

     <inv_id>280587</inv_id>

     <inv_number>274218</inv_number>

     <inv_date>20140401</inv_date>

     <inv_exclbtw>18.50</inv_exclbtw>

     <inv_btw>3.89</inv_btw>

     <inv_inclbtw>22.39</inv_inclbtw>

     <pdf>true</pdf>

     <invoiceprojects>

               <invoiceproject>

                      <project>SOHS35629</project>

                      <projectdescription>Locatie: zzzzz</projectdescription>

                      <orderreference>SOHS35629</orderreference>

                      <ordernumber>925402</ordernumber>

                      <portal_id></portal_id>

               </invoiceproject>

               <invoiceproject>

                      <project>SOHS35628</project>

                      <projectdescription>Locatie:xxxxxx</projectdescription>

                      <orderreference>SOHS35629</orderreference>

                      <ordernumber>925402</ordernumber>

                      <portal_id></portal_id>

             </invoiceproject>

     </invoiceprojects>

</invoice>

</invoices>

 

I currently have following written down. But the Project nodes stay empty...

 

<xsl:template match="/">
<invoices>
     <xsl:for-each select="fmp:FMPXMLRESULT/fmp:RESULTSET/fmp:ROW">
     <invoice>
     <inv_id><xsl:value-of select="fmp:COL[1]/fmp:DATA"/></inv_id>
     <inv_number><xsl:value-of select="fmp:COL[2]/fmp:DATA"/></inv_number>
     <inv_date><xsl:value-of select="fmp:COL[3]/fmp:DATA"/></inv_date>
     <inv_exclbtw><xsl:value-of select="fmp:COL[4]/fmp:DATA"/></inv_exclbtw>
     <inv_btw><xsl:value-of select="fmp:COL[5]/fmp:DATA"/></inv_btw>
     <inv_inclbtw><xsl:value-of select="fmp:COL[6]/fmp:DATA"/></inv_inclbtw>
     <pdf><xsl:value-of select="fmp:COL[7]/fmp:DATA"/></pdf>
     <invoiceprojects>
          <xsl:for-each select="fmp:COL[8]/fmp:DATA">
          <invoiceproject>
               <project><xsl:value-of select="fmp:COL[8]/fmp:DATA"/></project>
               <projectdescription><xsl:value-of select="fmp:COL[9]/fmp:DATA"/></projectdescription>
               <orderreference><xsl:value-of select="fmp:COL[10]/fmp:DATA"/></orderreference>
               <ordernumber><xsl:value-of select="fmp:COL[11]/fmp:DATA"/></ordernumber>
               <portal_id><xsl:value-of select="fmp:COL[12]/fmp:DATA"/></portal_id>
          </invoiceproject>
          </xsl:for-each>
     </invoiceprojects>
     </invoice>
</xsl:for-each>
</invoices>
 
Can anybody help me with this... thanksl!!!
Jeroen
 

Could you let us see the entire XSLT stylesheet, please? Best zip it and attach it to your post. Seeing the raw XML export would be helpful, too.

  • Author

Hi Comment,

 

Please find enclosed zip...

 

Thanks

jeroen

 

XML_problem.zip

The problem here is that when you do:

<invoiceprojects>
                    <xsl:for-each select="fmp:COL[8]/fmp:DATA">

you move the context to fmp:COL[8]/fmp:DATA. Then, when you try to output:

<project><xsl:value-of select="fmp:COL[8]/fmp:DATA"/></project>

you output an empty project, because the context node fmp:COL[8]/fmp:DATA has no child node fmp:COL[8]/fmp:DATA.

 

What you need to do is this:

...
<invoiceprojects>
    <xsl:for-each select="fmp:COL[8]/fmp:DATA">
        <invoiceproject>
            <xsl:variable name="pos" select="position()"/>
            <project><xsl:value-of select="."/></project>
            <projectdescription><xsl:value-of select="../../fmp:COL[9]/fmp:DATA[$pos]"/></projectdescription>
            <orderreference><xsl:value-of select="../../fmp:COL[10]/fmp:DATA[$pos]"/></orderreference>
            <ordernumber><xsl:value-of select="../../fmp:COL[11]/fmp:DATA[$pos]"/></ordernumber>
            <portal_id><xsl:value-of select="../../fmp:COL[12]/fmp:DATA[$pos]"/></portal_id>
        </invoiceproject>
    </xsl:for-each>
</invoiceprojects>
...

i.e. loop over the DATA elements of COL[8] and for each of these output first itself and then the corresponding DATA elements of the other columns originating in the child table.

  • Author

Brilliant Comment!

 

Tested it, works like a charm..

 

Thanks!

 

Jeroen

Create an account or sign in to comment

Important Information

By using this site, you agree to our Terms of Use.

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.