problem with variable
Here should go questions about transforming XML with XSLT and FOP.
-
- Posts: 10
- Joined: Thu Dec 07, 2006 12:08 pm
problem with variable
Post by heldopslippers »
I have a question:
I have this flexibel database that can containt multiple FIELDS:
I want that my XSL file counts how many FIELDS there are. I tryed serveral things but it doesn't work. this is one of my XSL files I tryed:
I hope someone can help me out.
gr "heldop"
I have this flexibel database that can containt multiple FIELDS:
Code: Select all
<?xml version="1.0" encoding="UTF-8" ?>
<FMPXMLRESULT xmlns="http://www.filemaker.com/fmpxmlresult">
<METADATA>
<FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="getal" TYPE="TEXT"/>
<FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="abc" TYPE="TEXT"/>
</METADATA>
</RESULTSET>
</FMPXMLRESULT>
Code: Select all
<xsl:stylesheet xmlns:xsl = "http://www.w3.org/1999/XSL/Transform" version = "1.0" >
<xsl:output method = "xml"/>
<xsl:template match = "/">
<xsl:element name="object">
<xsl:variable name="times2">0</xsl:variable>
<xsl:for-each select="/FS:FMPXMLRESULT/FS:METADATA/FS:FIELD" xmlns:FS="http://www.filemaker.com/fmpxmlresult">
<xsl:variable name="times">$times2+1</xsl:variable>
<xsl:variable name="times2">$times</xsl:variable>
</xsl:for-each>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
I hope someone can help me out.

gr "heldop"
-
- Posts: 10
- Joined: Thu Dec 07, 2006 12:08 pm
Post by heldopslippers »
thanxs for the replay george,
it works fine. But I still need a increment function. (I think that my exsample wasn't good enouth)
so here is one where I need increment:
I have here an XSL code.
the XSL file need to give eats a id number.
the output have to be this:
12
I hope someone can help me. I searched a lot for this. I couldn't vind a good selution.
gr "heldop"
it works fine. But I still need a increment function. (I think that my exsample wasn't good enouth)
so here is one where I need increment:
Code: Select all
<?xml version="1.0" encoding="UTF-8" ?>
<FMPXMLRESULT xmlns="http://www.filemaker.com/fmpxmlresult">
<METADATA>
<FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="getal" TYPE="TEXT"/>
<FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="abc" TYPE="TEXT"/>
</METADATA>
</RESULTSET>
</FMPXMLRESULT>
I have here an XSL code.
the XSL file need to give eats a id number.
the output have to be this:
12
Code: Select all
<xsl:stylesheet xmlns:xsl = "http://www.w3.org/1999/XSL/Transform" version = "1.0" >
<xsl:output method = "xml"/>
<xsl:template match = "/">
<xsl:element name="object">
<xsl:variable name="times">
<xsl:variable name="id'>0</variable>
<xsl:for-each select="/FS:FMPXMLRESULT/FS:METADATA/FS:FIELD" xmlns:FS="http://www.filemaker.com/fmpxmlresult">
<xsl:variable name="id"><xsl:value-of select="$id+1"/></variable>
<xsl:value-of select="$id"/>
</xsl:for-each>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
gr "heldop"
-
- Posts: 4141
- Joined: Fri Mar 28, 2003 2:12 pm
Post by sorin_ristache »
Hello,
I do not understand what is the expected output of the XSLT stylesheet that you need to write. What is 12? How should it be obtained from the input XML document? What is the expected output XML document?
Regards,
Sorin
I do not understand what is the expected output of the XSLT stylesheet that you need to write. What is 12? How should it be obtained from the input XML document? What is the expected output XML document?
Regards,
Sorin
-
- Posts: 10
- Joined: Thu Dec 07, 2006 12:08 pm
Post by heldopslippers »
oh sorry
end I see that I made a mistake in my XSL file (the variable "times" doesn't do enything)
this is the XSL file:
I wil discribe wat is supose to be doeing:
-it makes a variable ID
-it wil search for a field (<xsl:for-each select="/FS:FMPXMLRESULT/FS:METADATA/...)
-it puts in variable ID the ID+1 (the first time will be 0+1 =1 the second time 1+1 = 2)
-it wil write down the value of id (so in this case first 1 and then 2 (so 12))
-it wil search for the second time for a field \
-it puts in variable ID the ID+1
-it wil write down the value of id (so that wil be 1+1 = 2)
-it wil search for a field but won't find one so stops the for-each "loop"
-the XSL file is finist
I hope this wil be a bit clearer
gr "heldop"[/code]
end I see that I made a mistake in my XSL file (the variable "times" doesn't do enything)
this is the XSL file:
Code: Select all
<xsl:stylesheet xmlns:xsl = "http://www.w3.org/1999/XSL/Transform" version = "1.0" >
<xsl:output method = "xml"/>
<xsl:template match = "/">
<xsl:element name="object">
<xsl:variable name="id'>0</variable>
<xsl:for-each select="/FS:FMPXMLRESULT/FS:METADATA/FS:FIELD" xmlns:FS="http://www.filemaker.com/fmpxmlresult">
<xsl:variable name="id"><xsl:value-of select="$id+1"/></variable>
<xsl:value-of select="$id"/>
</xsl:for-each>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
I wil discribe wat is supose to be doeing:
-it makes a variable ID
-it wil search for a field (<xsl:for-each select="/FS:FMPXMLRESULT/FS:METADATA/...)
-it puts in variable ID the ID+1 (the first time will be 0+1 =1 the second time 1+1 = 2)
-it wil write down the value of id (so in this case first 1 and then 2 (so 12))
-it wil search for the second time for a field \
-it puts in variable ID the ID+1
-it wil write down the value of id (so that wil be 1+1 = 2)
-it wil search for a field but won't find one so stops the for-each "loop"
-the XSL file is finist
I hope this wil be a bit clearer

gr "heldop"[/code]
-
- Posts: 4141
- Joined: Fri Mar 28, 2003 2:12 pm
Post by sorin_ristache »
Hello,
It seems you want to count the FS:FIELD elements. You can do that with the following stylesheet that uses the count(/FS:FMPXMLRESULT/FS:METADATA/FS:FIELD) expression:
The output for the above XML input is:
If you want to read more about XSLT stylesheets you can find XSLT tutorials here and here.
Regards,
Sorin
It seems you want to count the FS:FIELD elements. You can do that with the following stylesheet that uses the count(/FS:FMPXMLRESULT/FS:METADATA/FS:FIELD) expression:
Code: Select all
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml"/>
<xsl:template match="/">
<xsl:element name="object">
<xsl:value-of select="count(/FS:FMPXMLRESULT/FS:METADATA/FS:FIELD)"
xmlns:FS="http://www.filemaker.com/fmpxmlresult"/>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
Code: Select all
<object>2</object>
Regards,
Sorin
Jump to
- Oxygen XML Editor/Author/Developer
- ↳ Feature Request
- ↳ Common Problems
- ↳ DITA (Editing and Publishing DITA Content)
- ↳ SDK-API, Frameworks - Document Types
- ↳ DocBook
- ↳ TEI
- ↳ XHTML
- ↳ Other Issues
- Oxygen XML Web Author
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Content Fusion
- ↳ Feature Request
- ↳ Common Problems
- Oxygen JSON Editor
- ↳ Feature Request
- ↳ Common Problems
- Oxygen PDF Chemistry
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Feedback
- ↳ Feature Request
- ↳ Common Problems
- Oxygen XML WebHelp
- ↳ Feature Request
- ↳ Common Problems
- XML
- ↳ General XML Questions
- ↳ XSLT and FOP
- ↳ XML Schemas
- ↳ XQuery
- NVDL
- ↳ General NVDL Issues
- ↳ oNVDL Related Issues
- XML Services Market
- ↳ Offer a Service