Jump to content
Claris Engage 2025 - March 25-26 Austin Texas ×

Is there a more efficient way?


This topic is 6614 days old. Please don't post here. Open a new topic instead.

Recommended Posts

Posted

Finally diving into xslt and hoping to learn something...

If I have a node like this:




 Stormy Monday

 Smoke on the Water

 Blue Monk





and there will never be more than one tune of each type of genre, then what is the most efficient way of extracting the jazz element? I  am using this code:



	

		

	

So, the result is "Blue Monk"

But, it seems to me that there is probably a much more efficient way of getting this same result. Any suggestions?

Posted (edited)

I assume that you don't want to have list that is separated by carriage returns, do you?




  







is shorter. All the jazz items come on one line (as in your previous code), but you can separate them by adding code such as 
 or so.



Even shorter is the following construct:



Let's assume playlist is the root node of your XML fragment:







selects all tune children of playlist with attribute genre = jazz.

Here you can't separate the items.

Selection of elements out of an XML tree or of whole axes is the strength of XPath.

Edited by Guest
If not code tag is used, the forum engine inserts spaces where they are not wanted.
Posted

Hi Martin,

I used your last example, and it does what I want. I need to parse a fairly large file with a lot of different nodes like the example I gave. So, the shorter I can make the xslt, the better.

Even with the official documentation on XSLT and XPATH, it really helps to have an example.

Thanks for the help.

Posted

Hmm, I seem to have another problem now. Suppose I have a node like this with the genre attribute missing from one of the elements:


 Happy Birthday

 Stormy Monday

 Smoke on the Water

 Blue Monk







Now I want to extract only the tune element that has no genre attribute. So, in this example I want to get: "Happy Birthday"



I tried:





but it doesn't work. Then, I thought Xpath might have an Exists() function so that I could use something like "not(Exists(tune/@genre))", but couldn't find anything like that. How would I handle this?

Posted

Thanks Fenton. As it turns out, some XSLT translators will work with the expression that I had tried, but not Filemaker's. Anyway, your's does the trick.

BTW, thank you for your past postings of XSL examples. I'm making great use of them on my current project.

This topic is 6614 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.