• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Newbie XSLT Question

 
Ranch Hand
Posts: 100
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Howdy all,

I have a problem I can't seem to figure out and was hoping you guys could help.

I have the following XML which is an extract from Rational Software Architect Modeler...


...what I'm wanting to do is extract information from this XML to turn into a CSV file. Basically I want to have my CSV file like this...

Component, Parent, Name, Complexity, Impact, Priority, Risk

..and from the above XML I'd have...

04.Participant, Citizenship, Delete Citizenship, 9, CRUDL, Should-have, Low

...with there being one line in the CSV file for each uml:UseCase xmi:type (i.e. Delete Citizenship, Update Citizenship, Read Citizenship etc...).

I have found the uml:Package and retrieved the name (04. Participant in this case) but I can't figure out how to then traverse to get to the first packagedElement and to each of the others to read their values - what am I missing?

Thanks,

Chris



 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are those elements in no namespace, or are they in the default namespace? It isn't possible to tell from your excerpt. In any case one of the packagedElement nodes is a child of the node that you already found, so it shouldn't be that hard to traverse to it. Anyway I don't see the XSLT you're asking about so it would just be guesswork for me to post some code which purported to be a solution.
 
Chris Bicnal
Ranch Hand
Posts: 100
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Fair enough - this is the code I have so far...



I'm reading the files I need to process from an XML file which has each file listed. This part of the puzzle is fine, it reads them all and outputs the name from the name attribute on the uml:Package node. As I say, the problem is trying to retrieve the name from the child packagedElement node.

 
Paul Clapham
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Which is why I asked whether that element was in the default namespace.
 
Chris Bicnal
Ranch Hand
Posts: 100
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok, so the XML file I'm working with is huge, so here's the top half of it which should answer your question.

I think the answer is yes (i.e. it's in the default namespace) but I figured you'd be the better person to answer that one!

 
Chris Bicnal
Ranch Hand
Posts: 100
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK, so from doing some Googling am I right in thinking that because my packagedElement element is in the default namespace my XSLT is ignoring it because it's looking for a packagedElement outside of a namespace....the default namespace is, after all, a namespace.

If that's the case, how can I tell my XSLT to look for packagedElement in the default namespace?

Thanks,

Chris
 
Paul Clapham
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Chris Bicnal wrote:OK, so from doing some Googling am I right in thinking that because my packagedElement element is in the default namespace my XSLT is ignoring it because it's looking for a packagedElement outside of a namespace....the default namespace is, after all, a namespace.



That's true, if your packagedElement element were in the default namespace. You've googled up the right stuff about the dreaded XSLT-1.0-default-namespace problem. But, but, I don't see anything which declares a default namespace at any level. (Hint: it would look like xmlns="....".) So it's just not in a namespace and you should be able to find it.

I think the reason you can't find it is that you aren't looking for it. Consider line 26 of your posted XSLT:

What you're selecting there is (I think) relative to the context node. And the context node at that point is "uml:Package" so here you're specifying "uml:Package/uml:Package/packagedElement" -- which doesn't exist. Try
 
Chris Bicnal
Ranch Hand
Posts: 100
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for that Paul.

What you're saying makes sense, although it still doesn't seem to be working for me.

I've now updated my XSLT to look like this....


...and the only output I get is;

Component^Business UseCase Name^UseCase Name^Complexity^Impact^Priority^Risk
07. Product Delivery Case^
18. Reporting^
10. Eligibility^
11. Benefit Issuance^
16. Interfaces^
17. Data Migration^
06. Integrated Case^
12. Financial^
08. Liability Case^

...which tells me that it's iterating over each file correctly, and reading the name from the uml:Package element, but it still doesn't find the packagedElement. I've tried all sorts of combinations on the apply-templates including //packagedElement and it still doesn't find anything!



Chris
 
Paul Clapham
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, I'm stuck. I haven't done any serious XSLT for quite a while so maybe I'm missing something very obvious. I don't know what those processing-instructions at the beginning do, but probably in the context of an XSL transformation they don't do anything.

You could always try an open <xsl:apply-templates>, i.e. one which selects everything, and then put in an <xsl:template> which matches everything, and put debugging code in it to see what you get. Or you could try the tack of match="*[local-name() = 'packagedElement'] just in case there's a namespace we didn't notice. Or maybe g tsuji will happen by and solve the whole thing right away.
 
Ranch Hand
Posts: 734
7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If only I can help!...

First, I am surprised you actually got "07. Product Delivery Case^" (or 04.Participant in the first post for that matter) etc...

[1] The document() apply-templates should be read like this.

assuming all the prefixes were properly declared in the xsl:stylesheet or alike.

[2] The might be a typo in the first packageElement which should be an empty tag like the following siblings? (but then why the following packagedElement be indented more?) If that is not a typo, make sure you know packagedElement is nested into itself and deal with it accordingly.


[3] And then if you only want to select the first three packagedElement with the specific combination of xmi:type and xmi:id as criteria so that the output stop from "Delete Citizenship", make sure you put some predicates in the select of the xsl:apply-templates. And there after, go/traverse to ACESProfic:SUC for continuing extracting data...

 
Chris Bicnal
Ranch Hand
Posts: 100
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK, so once I included the xmi namespace into the XSLT it worked!

My next problem is to figure out how to change the flow of the XMI depending on whether the packagedElement I'm processing has an xmi:type of uml:Package versus uml:UseCase.

Any ideas on that one?
 
Paul Clapham
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Chris Bicnal wrote:OK, so once I included the xmi namespace into the XSLT it worked!



Of course!

My next problem is to figure out how to change the flow of the XMI depending on whether the packagedElement I'm processing has an xmi:type of uml:Package versus uml:UseCase.



<xsl:choose> or <xsl:if> to do conditional processing.

You already know how to use the attribute axis, I see.

For selecting and matching there's also the predicate:
">
 
Are you okay? You look a little big. Maybe this tiny ad will help:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic