|
Rank: Member
Joined: 8/18/2017 Posts: 11 Location: Netherlands
|
I'm trying to build an Xpath condition which only shows an xml element when actual filled. Otherwise leave alone, no space or empty value. It sounds really simple but I can't find an "if exists" condition. There is if-then-else but I'm not sure how to set this up in XPath/StyleVision. See sps screenshot below.
Line 4, where the cbc:BuildingNumber element shows, starting with the comma I want to hide the cbc:AdditionalStreetName element when there is no value given in XML. See attached files. How would the condition look like? Should I use Xpath for that?File Attachment(s): UBLSimple.sps (10kb) downloaded 478 time(s). 2017-0098.xml (14kb) downloaded 678 time(s). schema.xsd (49kb) downloaded 725 time(s).
|
|
Rank: Member
Joined: 8/18/2017 Posts: 11 Location: Netherlands
|
I've tried the following but that condition won't validate correctly:
if (cbc:AdditionalStreetName) then cbc:AdditionalStreetName else
|
|
Rank: Advanced Member
Joined: 12/13/2005 Posts: 2,856 Location: Mauritius
|
But if there is no content it won't appear. What's exactly your problem - the additional empty line? Also, you have to differentiate between element being present with no value inside, and no element at all. What is your case? And attach your schema, currently one cannot open your design.
Just by guessing what you want, all you need is to move comma and space within cbc:AdditionalStreetName
|
|
Rank: Member
Joined: 8/18/2017 Posts: 11 Location: Netherlands
|
The content needs NOT to be displayed if empty. That's why after the "else" I didn't enter any clause.
So when <cbc:AdditionalStreetName> doesn't have a value, skip it and move to the next (cbc:PostalZone>). The ", " (comma and space) also need not to be displayed. I'll add the schema to the first post.
The condition
Code:if (cbc:AdditionalStreetName) then cbc:AdditionalStreetName else doesn't work in the XPath editor. I can't close the editor (by clicking OK button) because the syntax doesn't comply.
|
|
Rank: Advanced Member
Joined: 12/13/2005 Posts: 2,856 Location: Mauritius
|
To correct your XPath put () after else
() means empty sequence. But once again, there is no need to put this in an if-else clause, because a missing element doesn't render anyway.
|
|
Rank: Member
Joined: 8/18/2017 Posts: 11 Location: Netherlands
|
You are right Sir! I'm sorry, I just realized that empty elements don't display! I left them alone and made the text before an element conditional. In this example the conition is as follows:
Code:if (cbc:AdditionalStreetName) then ", " else ()
I made a bunch of other conditions the same way. They all work beautiful. Thank you.
|
|
Rank: Member
Joined: 8/18/2017 Posts: 11 Location: Netherlands
|
I'm now trying to achieve the following.
I need to add telephone/fax/e-mail and other contact details in the mix. They display perfectly but I want to add "tel:"/"fax:"/"email:" before each value conditionally. Not all of these details are mandatory, some fields sometimes just aren't there in the XML file. I've entered the following XPath condition:
Code:if (cac:Contact/cbc:Telephone) then "tel: " else () But this doesn't work. In the example XML given in this thread, the telephone number does exist. The phonenumer itself displays correct on the PDF. What's wrong with the XPath syntax? I have a feeling that the sub ("/") is not recognized.
|
|
guest |