June 7, 201114 yr Hi guys ! I am trying to supply some xml-document using the FileMaker XML/XSL possibilities. Now it seems the software from the other side asks me to supply <elem xsi:nil="true"/> in stead of a <elem/>. What do I have to do add to my stylesheet to create empty like this ? TIA ! Joost
June 8, 201114 yr Author Try: <elem xmlns:xsi="http://www.w3.org/2001/XMLSchema" xsi:nil="true"/> Great thanks ! Emmm, where do i put it ? ( in this partial xslt ? ) Thnx again.... <?xml version='1.0' encoding='UTF-8'?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fmp="http://www.filemaker.com/fmpxmlresult" exclude-result-prefixes="fmp"> <xsl:output version="1.0" encoding="utf-8" indent="yes" method="xml" /> <xsl:template match="/"> <soap:envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> <soap:header> <authenticationheader xmlns="https://www.kwaliefyXml.nl/KwaliefyAanlevering"> <username> usr </username> <password> pss </password> </authenticationheader> </soap:header> <soap:body> <wsaanlevering xmlns="https://www.kwaliefyXml.nl/KwaliefyAanlevering"> <naamaanlevering> V999801_P1234657_201001031131 </naamaanlevering> <aanlevering> <kwaliefyaanlevering xmlns="https://www.kwaliefyXml.nl/KwaliefyAanlevering" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <xsl:call-template name="praktijk" /> <locatie> <xsl:call-template name="locatie_data" /> <xsl:for-each select="fmp:FMPXMLRESULT/fmp:RESULTSET/fmp:ROW"> <behandelverslag> <xsl:variable name="recNum"> <xsl:value-of select="position()" /> </xsl:variable> <xsl:call-template name="Basisgegevens"> <xsl:with-param name="volgnummer"> <xsl:value-of select="$recNum" /> </xsl:with-param> </xsl:call-template> <xsl:call-template name="Datums" />
June 8, 201114 yr where do i put it ? I don't know. Didn't you say you need this instead of <elem/>? I don't see <elem/> in your stylesheet.
June 8, 201114 yr Author I don't know. Didn't you say you need this instead of <elem/>? I don't see <elem/> in your stylesheet. OK, I thought it was a generic solution. So, that if a tag were to remain empty, this would be added. So, logically I'd have to put this peace of code in every tag that needs to be empty in this way. I'll try that !
June 8, 201114 yr I thought it was a generic solution. So, that if a tag were to remain empty, this would be added. It depends on your schema - and on your data. See: http://www.w3.org/TR/xmlschema-0/#Nils Using their example, if your shipDate were the third field in your export order, you would use something like: <xsl:choose> <xsl:when test="string(fmp:COL[3])"> <shipDate> <xsl:value-of select="fmp:COL[3]"/> </shipDate> </xsl:when> <xsl:otherwise> <shipDate xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/> </xsl:otherwise> </xsl:choose> to signify that the absence of shipDate is intentional.
June 10, 201114 yr Author It depends on your schema - and on your data. See: http://www.w3.org/TR/xmlschema-0/#Nils Using their example, if your shipDate were the third field in your export order, you would use something like: <xsl:choose> <xsl:when test="string(fmp:COL[3])"> <shipDate> <xsl:value-of select="fmp:COL[3]"/> </shipDate> </xsl:when> <xsl:otherwise> <shipDate xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/> </xsl:otherwise> </xsl:choose> to signify that the absence of shipDate is intentional. Yes, thnx for that bit of info. However, isn't that a lot of work for say 58 tags do make (quite a bit of copy and pasting) ? On the other hand, I could try to make a xsl:template that takes a tag name and does the testing... and builds the correct tag ? Do you know if it is possible to do that ? So, in your example... something like : <xsl:call-template name="tstForEmpty"> <xsl:with-param name="tagName"><xsl:value-of select="shipDate"/></xsl:with-param> <xsl:with-param name="tagValue"><xsl:value-of select="string(fmp:COL[3])"/></xsl:with-param> </xsl:call-template> And that would build the required result ...
June 10, 201114 yr I could try to make a xsl:template that takes a tag name and does the testing... and builds the correct tag ? Do you know if it is possible to do that ? Yes, of course it's possible. And there are probably other options as well - I just don't see the entire picture here. isn't that a lot of work for say 58 tags You export 58 fields?
June 15, 201114 yr Author Yes, of course it's possible. And there are probably other options as well - I just don't see the entire picture here. You export 58 fields? Yes there are 58 fields to export. It is quite a lengthy document I have to produce. What info do you need to see the entire picture ? Or at least enough ? My xsl is currently around 1000 lines long. Most of the tags are Dutch, so that would probably limit it in easiness to read. I'll up the xsd and xsl with this post. Maybe you can give me some pointers... kwaliefy.xsd.zip kwaliefy.xsl.zip
June 15, 201114 yr What info do you need to see the entire picture ? I would need to know what comes in (the exported data) and what is supposed to come out. It seems you are doing quite a lot of processing, but without knowing what problems you are trying to solve I cannot follow it. Most of the tags are Dutch, so that would probably limit it in easiness to read. That too... In any case, you could do something like: ... <shipDate> <xsl:call-template name="nilElement"> <xsl:with-param name="value" select="fmp:COL[3]"/> </xsl:call-template> </shipDate> ... <xsl:template name="nilElement"> <xsl:param name="value"/> <xsl:choose> <xsl:when test="string($value)"> <xsl:value-of select="$value"/> </xsl:when> <xsl:otherwise> <xsl:attribute name="xsi:nil" namespace="http://www.w3.org/2001/XMLSchema-instance">True</xsl:attribute> </xsl:otherwise> </xsl:choose> </xsl:template>
July 6, 201114 yr Author I would need to know what comes in (the exported data) and what is supposed to come out. It seems you are doing quite a lot of processing, but without knowing what problems you are trying to solve I cannot follow it. That too... In any case, you could do something like: ... <shipDate> <xsl:call-template name="nilElement"> <xsl:with-param name="value" select="fmp:COL[3]"/> </xsl:call-template> </shipDate> ... <xsl:template name="nilElement"> <xsl:param name="value"/> <xsl:choose> <xsl:when test="string($value)"> <xsl:value-of select="$value"/> </xsl:when> <xsl:otherwise> <xsl:attribute name="xsi:nil" namespace="http://www.w3.org/2001/XMLSchema-instance">True</xsl:attribute> </xsl:otherwise> </xsl:choose> </xsl:template> Thnx ! That is what I thought I had to do... One more question if I may... Sometimes I get this error : The prefix "xsi" for attribute "xsi:nil" associated with an element type X is not bound. Can you explain in plain English what this means ? And how do I solve it ?
July 6, 201114 yr It means that the processor cannot find the definition (more precisely, the namespace binding) of the prefix "xsi'. Where and when do you get this error? In my example, the namespace binding is done in the xsl:attribute element itself. If you add a namespace binding declaration: xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" to the top of the document, you can then use it anywhere in the document.
Create an account or sign in to comment