Kordolio Posted October 19, 2010 Share Posted October 19, 2010 Hello,I am totally new to the subject.My problem:Here's a part of an xml:<ProductView id="id4" ruleRefs="#id2" rootRefs="id7" primaryOccurrenceRef="id7"><ApplicationRef application="Teamcenter" label="S_IxJihkg8VtHC/QYMx0zZEg8VtHC/AAAAAAAAAAAAAA/BOM"></ApplicationRef><UserData id="id3" type="TC Specific Properties"><UserValue value="imprecise" title="BOM_precision_type"></UserValue></UserData><Occurrence id="id7" instancedRef="#id154" occurrenceRefs="id16 id51 id11 id56 id72 id140"><ApplicationRef application="Teamcenter" label="S_IxJihkg8VtHC/"></ApplicationRef><UserData id="id6"><UserValue type="reference" value="" title="bl_uom"></UserValue><UserValue type="int" value="1" title="bl_pack_count"></UserValue><UserValue value="" title="bl_sequence_no"></UserValue></UserData><UserData id="id8" type="AttributesInContext"><UserValue value="" title="AO_ID"></UserValue><UserValue value="" title="SequenceNumber"></UserValue><UserValue value="" title="OccurrenceName"></UserValue><UserValue value="" title="Quantity"></UserValue></UserData><Transform id="id5">1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1</Transform></Occurrence><Occurrence id="id11" instancedRef="#id19" parentRef="#id7"><ApplicationRef application="Teamcenter" label="S_IxJihkg8VtHC/ycJxJmmTg8VtHC/"></ApplicationRef><UserData id="id10"><UserValue type="reference" value="" title="bl_uom"></UserValue><UserValue type="int" value="3" title="bl_pack_count"></UserValue><UserValue value="20" title="bl_sequence_no"></UserValue></UserData><UserData id="id12" type="AttributesInContext"><UserValue value="" title="AO_ID"></UserValue><UserValue value="20" title="SequenceNumber"></UserValue><UserValue value="" title="OccurrenceName"></UserValue><UserValue value="" title="Quantity"></UserValue></UserData><UserData id="id13" type="InstanceNotes"><UserValue value="NOGA_TESTOWA" title="UG NAME"></UserValue><UserValue value="RM%UL=V1.0 PH=SKCxJihkg8VtHC O0000003a0000001c" title="UG ENTITY HANDLE"></UserValue></UserData><Transform id="id9">1 0 0 0 0 1 0 0 0 0 1 0 0 0.5600000000000001 0 1</Transform></Occurrence><Occurrence id="id16" instancedRef="#id19" parentRef="#id7"><ApplicationRef application="Teamcenter" label="S_IxJihkg8VtHC/CYOxJqt2g8VtHC/"></ApplicationRef><UserData id="id15"><UserValue type="reference" value="" title="bl_uom"></UserValue><UserValue type="int" value="1" title="bl_pack_count"></UserValue><UserValue value="20" title="bl_sequence_no"></UserValue></UserData><UserData id="id17" type="AttributesInContext"><UserValue value="" title="AO_ID"></UserValue><UserValue value="20" title="SequenceNumber"></UserValue><UserValue value="" title="OccurrenceName"></UserValue><UserValue value="" title="Quantity"></UserValue></UserData>....I have an xsl for transforming it into html.Now what I want is to create a parameter which will be preceding (or following) of the "instancedRef" value.The correct syntax for the "current" instancedRef value is:<xsl:variable name="instRef" select="//plm:PLMXML/plm:ProductView/plm:Occurrence[@id=$occid]/@instancedRef" />What will the syntax for the preceding/following look like?Thanks in advance!Regards Link to comment Share on other sites More sharing options...
Martin Honnen Posted October 19, 2010 Share Posted October 19, 2010 Your variable holds a node-set (XSLT 1.0) or sequence (XSLT 2.0) of attribute nodes. In the XSLT/XPath/XQuery data model attribute nodes do not have any order so there is nothing like a preceding or following attribute node, if that is what you are looking for.Other than that you have explained what kind of value you are looking for. Link to comment Share on other sites More sharing options...
Kordolio Posted October 19, 2010 Author Share Posted October 19, 2010 Thank you for responding, but please do not forget that I have very little experience with xml, xsl etc.What you are saying is that it is not possible to get the previous/next variable value at all?Well, the resulting html produces a table list of items. Some of the items occur several times and my goal is to get only the last occurance of the item, as the last one holds the total number of items ("bl_pack_count" value)(here in xml it is the first occurance, strangely enough).My idea was:1. To compare the "instancedRef" value and, if the same as the value in previous item, do not display it (using xsl:when) (which I thought was possible) or2. To count all the items with the same "instancedRef" value and put a table entry with the result (but I lack knowledge here).Would appreciate any help.RegardsPs. The xml is 1.0 versionPs2. If necessary, I can provide the docs. Link to comment Share on other sites More sharing options...
Martin Honnen Posted October 19, 2010 Share Posted October 19, 2010 I don't understand what you want to achieve. Your variable selects attributes named 'instancedRef' on elements named 'Occurrence'. Do you want to select or find another attribute (like 'occurrenceRefs') on that same element? Link to comment Share on other sites More sharing options...
Kordolio Posted October 19, 2010 Author Share Posted October 19, 2010 No, the instancedRef variable is only an example and an anchor point for me.What I get from it all, is a html with the table of items. These items sometimes occur more than once (they are nothing more than duplicates, irrelevant for me). If they occur more than once, the last item holds all the relevant data and therefore is the most important for us.What I want to achieve is to get rid of those duplicates.So in the final result the table should contain only these items which:1. Occur once2. Are the last one, if they have duplicates.Does it make sense to you?Regards Link to comment Share on other sites More sharing options...
boen_robot Posted October 19, 2010 Share Posted October 19, 2010 You have to keep in mind that there's just one instancedRef attribute... per element. Therefore, to get the next value of the attribute, you need to first get a collection of all elements that have it, or all you're interested in. Only then should you look for a way to go over a particular subset of the collection, and extract whatever you want from it.And speaking of which... "following"... following what?Assuming only Occurrence elements hold this attribute (as is the case in your sample XML), and that you need to traverse all after a particular known position (in this example, all after the first), you can do <xsl:for-each select="//plm:PLMXML/plm:ProductView/plm:Occurrence[1]/following-sibling::plm:Occurrence"><xsl:value-of select="@instancedRef" /></xsl:for-each> Or have I too misunderstand what you're asking? Link to comment Share on other sites More sharing options...
Kordolio Posted October 20, 2010 Author Share Posted October 20, 2010 Well, we will do it another way. I will insert the 3 files on my ftp soon (I see no option to insert files here) and maybe it will help to explain, what I have and what I want.Regards and thanks for help so far! Link to comment Share on other sites More sharing options...
Kordolio Posted October 20, 2010 Author Share Posted October 20, 2010 OK, here they are:http://aquila-it.pl/download/xml.xmlhttp://aquila-it.pl/download/xsl.xsl http://aquila-it.pl/download/html.htmlhttp://aquila-it.pl/download/final.jpgThe html file is what I get at the moment. My problem is that in html I get the list of all items "separately". For example the item "noga testowa" occurs in total 3 times in the database. So in the html only the third occurance (with Qty value of 3) is important for us. Therefore I would like to hide the 2 first occurences of this item. The same goes for "element blatu testowy", which occurs 5 times. The jpg file is what I actually would like to obtain in html. It contains items and the number of "occurances" of the items (Pack count).Hope this clarifies the case.Please let me know if you need any further information.Regards Link to comment Share on other sites More sharing options...
boen_robot Posted October 22, 2010 Share Posted October 22, 2010 I'm not sure how to do what you're asking for in a single XSLT transformation, especially XSLT 1.0. Hopefully, Martin can suggest a better way, but the only way I can think of is to take the resulting table, then traverse it with DOM in some language (PHP, ASP.NET, etc.), and eliminate any unnecesary nodes. How exactly do you do it in DOM? Multiple ways, with varying CPU and RAM consumption, depending on what's more important for you. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.