cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - You can change your system assigned username to something more personal in your community settings. X

xpath and docx exports

KaelLizak
14-Alexandrite

xpath and docx exports

xpath and docx exports (migrated thread) Posted: Aug 22, 2012 2:05 PM

jjohnson  

Posts: 5
  Registered: Jul, 2012


First off, the documentation on this stuff needs some work.  I couldn't find anything on this website that talks about xpath.  You have to actually download their docs before you even see it mentioned...

Here's what I'm trying to do.  Its a little more complicated than I'm going to describe here, but if I can get this bit to work, I can figure out the rest. 

I want to have a query that says: if this category=heading, and it has a descendant with a particular value in another field, do something.  You can't nest IF statements from what I've read (though I haven't actually tried it).  I would expect my code to look something like this (forgive the syntax):

I've created a field called 'columncount'

<%if(({Category}=="Heading") and ({xpath:name(./@columncount)}=="5"))%>
True
<%else%>
False
<%endif%>

From experimentation with xpath, I can only seem to get it to count things and to spit out "Category" and "Item" using 'name'.  So if I do name() I get 'Item', or if I do name(@*) I get 'col09' which is a field I created, but no idea why its returning it (its not the first or last field etc).  If I do name(//@*) I get 'Category'.

For giggles I did this:

<%{Section}%>
<%{xpath:name(*)}%>
<%{xpath:name(//@*)}%>
<%{xpath:name(*[@*])}%>
<%{xpath:name(node())}%>

Which should return the values of all of those for each line in a document. Whats interesting is that for everything thats <= 2 levels deep, i.e.:
1 (1 level)
1.1 (2 levels)
1.1.1 (3 levels)

I get:

1 - the section number
Item
Category
Item
Item

For > 2 levels I get

1.1.1
Category

I'm no expert with xml or xpath, but since there's a huge lack of documentation on this, I can only experiment and draw my own conclusions.  None of the example export files seem to go into much detail or do anything particularly fancy.

Why are there no nested IF statements?  No For loops, no variables or functions? 

    

          

Re: xpath and docx exports Posted: Aug 22, 2012 4:02 PM
Posted By:   jjohnson     Posts: 5 /  Registered: Jul, 2012  
I think I can simplify the problem a bit:

How do I write into my docx something that will tell me the previous line's category or the next lines category, without actually getting to that line so:

if (category of current line) = comment then
  give me the category of the previous line
endif

  

          

Re: xpath and docx exports Posted: Aug 24, 2012 4:54 AM
Posted By:   matthias.rump     Posts: 166 /  Registered: Mar, 2008  
Hi Mr Johnson,

to be honest, I'm a little confused about yout intention in using the Word Export.

As far as I know the main intention of this feature is to Export Requirements Documents from Integrity. For this usecase you would normally not need any xpath expression.

If you have a field named "columncount" you can access it in the word template via <%{columncount}%>.

It is possible to use IF-clauses in the word template e.g.
lt;%beginContent%>


<%beginLevel 1%>
<%if ({RQ_Category} == "Heading")or({RQ_Category} == "Document")%>
1     <%{RQ_Text} richcontent="false"%>
<%elseif {RQ_Category} == "Comment"%>
<%{RQ_Text}%>
<%else%>
MKS ID =  <%{ID}%>
EC-Kategory= <%{RQ_Category}%>     Status = <%{State}%>
Custom ID:
<%{Custom_ID}%>     Einstufung (Kunde):
<%{EPEC_CustomerCategory}%>     Ansprechpartner:
<%{ContactPerson}%>
Quelle:
<%{RQ_Text}%>
Datum      Kommentare
<%{RQ_Revision Date}%>     <%{EPEC_Comment}%>

<%endif%>
<%endLevel%>

<%beginLevel 2%>
<%if ({RQ_Category} == "Heading")or({RQ_Category} == "Document")%>
1.1     <%{RQ_Text} richcontent="false"%>
<%elseif {RQ_Category} == "Comment"%>
<%{RQ_Text}%>
<%else%>
MKS ID =  <%{ID}%>
EC-Kategory= <%{RQ_Category}%>     Status = <%{State}%>
Custom ID:
<%{Custom_ID}%>     Einstufung (Kunde):
<%{EPEC_CustomerCategory}%>     Ansprechpartner:
<%{ContactPerson}%>
Quelle:
<%{RQ_Text}%>
Datum      Kommentare
<%{RQ_Revision Date}%>     <%{EPEC_Comment}%>

<%endif%>
<%endLevel%>

<%beginLevel 3%>
.....


  

          

Re: xpath and docx exports Posted: Aug 24, 2012 1:03 PM
Posted By:   jjohnson     Posts: 5 /  Registered: Jul, 2012  
FYI, I'm using Integrity 10.0 in case you were curious - not that it really makes a difference here.

Sorry if what I wrote was a bit confusing.  Our customers are fairly insistent on the kinds of documents we give them.  Its not very practical for us to have to change the export document every time they want to add or remove a requirement, so formatting every line in the export Word document for every line in the requirement document can be time consuming, so I've written a fairly dynamic export document that will allow for changes and additions to the requirements document. 

I've added a number of fields that can be used in a somewhat dynamic manner. I have a field called Column Count which is basically just a way for the user to specify how many columns (fields) are used in that section. Next to that I have col01, col02, col03 up to col10.  I use this to generate a table.  When the gateway looks at the requirements document and sees a number in the column count, it uses a section of my word export document that has that number of columns prepared for it and fills them accordingly.

Its difficult to describe without actually showing you.  The customer has a document that they want our requirements output to look like so we have to work within those constraints.  In that document is a few tables on pages that are set to landscape instead of portrait.  In word you do this by creating a 'next page' section break before and after the section you want to be landscape. 

I was trying to figure out a way to have the word export file determine which tables were going to have more than a certain number of columns (in my case 6 or more) and have it automatically insert the needed section breaks.  Obviously I could do this if I was hitting each row at a time in the export document (i.e. using 'beginLevel') but because I'm trying to keep this as dynamic as possible I was trying to figure out a way to have it do this for me. I found that this worked to an extent:

<%if((({Category}=="Heading") or ({Category}=="Sub-Heading")) and ({xpath:.//@ColumnCount > 6}=="true"))%>
-----section break------
<%endif%>
<%if  *code for my tables* %>
table with > 6 columns
<%endif%>
-----section break-----


But the closing section break caused issues no matter where I put it whether before the endif or after so I had to give up on that. 

I'm not a coder so this is something I've been beating my head against and I get the impression that I'm trying to do a lot more with this stuff than were the intentions when this part of integrity was put together. The example files don't go into much detail about what different things you can do and only show a few options.

If you want to see what I came up with, I'll see if I can sanitize it a bit and post it here.

  

          

Re: xpath and docx exports Posted: Aug 27, 2012 11:39 AM
Posted By:   matthias.rump     Posts: 166 /  Registered: Mar, 2008  
I think I hear you now.

First of all, I'm customer and not MKS developer just as you, so for your really tricky plan, you should contact MKS support directly.

As far as I know the Word Export, there is no support for "nested" IF clauses, so your code snippet will never work, no matter where you put the "--section break--".

Nevertheless, something like

<% if((({Category}=="Heading") or ({Category}=="Sub-Heading")) and ({xpath:.//@ColumnCount < 6}=="true"))%>
-----section break------
table with < 6 columns
-----section break-----
<%endif%>

<%elseif((({Category}=="Heading") or ({Category}=="Sub-Heading")) and ({xpath:.//@ColumnCount = 6}=="true"))%>
-----section break------
table with 6 columns
-----section break-----
<%endif%>

<%elseif((({Category}=="Heading") or ({Category}=="Sub-Heading")) and ({xpath:.//@ColumnCount = 7}=="true"))%>
-----section break------
table with 7 columns
-----section break-----

<%endif%>


.. and so on...


should work.
It's far from elegant, but as long as it does the job.


HTH Matthias

PS: I'love to see your final solution here

  

            

Re: xpath and docx exports Posted: Aug 28, 2012 2:11 PM
Posted By:   jjohnson     Posts: 5 /  Registered: Jul, 2012  
Ok, I think I sanitized the attached docs sufficiently... 

So what I've attached works.  I added a screen shot that will show what it looks like in integrity.

RequestedExportTemplate is what they wanted it to look like.
WordExport-REQ is what I created
screenshot - integrity

Kind Regards,
Kael Lizak

Senior Technical Support Engineer
PTC Integrity Lifecycle Manager
0 REPLIES 0
Top Tags