5 users online. Create an account or sign in to join them.Users
Get DS elements for empty fields?
This is an open discussion with 7 replies, filed under Troubleshooting.
Search
Post your XSLT.
As far as I know, no. If the field is empty, Symphony will not output the element in the XML. This is great for usual cases since testing values is simply a case of checking of existence of an XML node.
Not ideal, but you could have a variable containing a comma delimeted list of all field names. For each entry you recurse through this array looking for the fields in the current entry.
As you say, not pretty.
Why don't you just check if the element is present in the XML?
<xsl:choose>
<xsl:when test="/data/your-datasource/entry/your-element">... (element is present) ...</xsl:when>
<xsl:otherwise>... (element is not present) ...</xsl:otherwise>
</xsl:choose>
I'm guessing ashooner wants a generic XML to CSV stylesheet without the need to check every node explicitly. Using the variable containing a string of all field names would allow you to store this information once and iterate through it to create both the column headings and check the data integrity.
Thanks for the ideas. Nick, this is what I've ended up doing. The only better option I could imagine was to find the entry element with the most child elements (i.e. with the most columns for the csv) and use those fields as the model instead of the string you suggest, but I couldn't figure an efficient way to do that.
I suppose you could write a custom DS ("datasource-fields") which, when given a section ID, looks into the database and finds all fields within that section, directly using SQL. Could write them back into the XML, and you can iterate through them this way.
For posterity, The Section Schemas datasource extension has solved this problem. Alternatively, I had come to another solution where I created a ‘key entry’ that had the name of each field as its value (denoted with a checkbox).
Create an account or sign in to comment.
I am trying to output to csv, but my datasource will only output elements for fields that have content. This is a problem since I need my xsl to handle every field even if there is no content (to add the comma). Is there a way to force a datasource to output elements even if they are empty?
I'm working around it but it isn't pretty.
thanks