Solved

How to construct condition in xsl

Posted on 2013-05-20
5
273 Views
Last Modified: 2013-05-20
I need to modify the attached XSL so that it returns information for fields that are empty in the input.

I.E. If the input contains
<inmr0:CatNotes />,
I need the XSL to return
<PropertyValue name="Notes" />
rather than nothing.

To clarify: I don't know how to set up conditions in the XSL so that it doesn't completely ignore the the empty fields in input.

I've attached the XSL along with sample input. The input contains a number of empty fields, including these:

<inmr0:CatNotes />
<inmr0:CatISBN />
<inmr0:CatFileName />

However, as I said, such fields make NO APPEARANCE in the output. What I need to see for them is this:

<PropertyValue name="Notes" />
<PropertyValue name="ISBN" / >
<PropertyValue name="Document File Name" / >

Who knows how to do this?
NeedsAdjustment.xsl
inputTEST.xml
inputTEST-out-problem.xml
0
Comment
Question by:GessWurker
  • 3
  • 2
5 Comments
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 39181399
The condition already is in your XSLT

                     <xsl:for-each select="inmr0:CatNotes[string(.)]">

does something for every CatNotes that ahs content
[string(.)] actually excludes all the notes that don't have content

if you remove all the occurences of [string(.)] from your stylesheet it will do what you need
0
 

Author Comment

by:GessWurker
ID: 39181468
Hi. And thanks. Nearly there. However... there's one problem: The concatentation for Document File Name. With an empty CatFileName, I end up with this:

<PropertyValue name="Document File Name">F:\Program Files\Inmagic\Genie\DocumentFolder\</PropertyValue>

I need to end up with this:

<PropertyValue name="Document File Name" />
0
 
LVL 60

Accepted Solution

by:
Geert Bormans earned 500 total points
ID: 39181513
<xsl:for-each select="inmr0:CatFileName">
                        <PropertyValue name="Document File Name">
                          <xsl:if test="string(.)">
                            <xsl:value-of select="concat('F:\Program Files\Inmagic\Genie\DocumentFolder\', .)"/>
                          </xsl:if>
                        </PropertyValue>
                      </xsl:for-each>
0
 

Author Comment

by:GessWurker
ID: 39181637
Thanks. Works as advertised! (i.e., perfectly!)

Cheers!
0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 39181681
welcome
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Which XML parser should I used for my requirement 11 76
How can I assign SimpleXMLElements to variables? 5 67
MS SQL Database Generating XML using query 21 50
XSLT XML 4 28
The Client Need Led Us to RSS I recently had an investment company ask me how they might notify their constituents about their newsworthy publications.  Probably you would think "Facebook" or "Twitter" but this is an interesting client.  Their cons…
Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question