Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 16th, 2008, 05:25 AM
Authorized User
 
Join Date: Aug 2008
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default Reg: preceding axis scoping

<xsl:for-each select="//eSubpackages/eClassifiers">
<xsl:variable name="classifier" select="@name"/>
<xsl:for-each select="eStructuralFeatures/eAnnotations/details[@key='tabGroup'][not(@value=preceding::eClassifiers/[@name=$classifier]/eStructuralFeatures/eAnnotations/details[@key='tabGroup']/@value)]">

Can some one help me why the preceding axis is not working when I try to scope (the element where I would like to search) as in the sample above?


 
Old October 16th, 2008, 05:31 AM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

I think
preceding::eClassifiers/[@name=$classifier]
needs to be
preceding::eClassifiers[@name=$classifier]

--
  Martin Honnen
  Microsoft MVP - XML
 
Old October 16th, 2008, 05:35 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

You say its not working but you don't say what you are trying to achieve - nor what error you are getting (if indeed you are getting one). Why is it not working?

You also don't show us an example of your XML, so we have no idea what the above is going to generate...


/- Sam Judson : Wrox Technical Editor -/
 
Old October 16th, 2008, 05:36 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

The only thing obviously wrong with your code is a syntax error

preceding::eClassifiers/[@name=$classifier]

I suspect the "/" should simply be removed.

If that's not your problem, then we would need to know something about your input and your desired output.

I don't know what you mean by "try to scope (the element where I would like to search)".

I should also point out that this construct is likely to be very inefficient if your source document is large. To eliminate duplicates, it's much more efficient to use xsl:for-each-group in XSLT 2.0, or Muenchian grouping in XSLT 1.0.

Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer's Reference
 
Old October 16th, 2008, 06:00 AM
Authorized User
 
Join Date: Aug 2008
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default

No issue with the syntax. That was a typo in the post. Sorry for that.I have no issue with efficiency as the documents are not huge in size. What I could not get right was duplicate checking within a particular subtree rather than the whole document

Following is the info about the issue

<xsl:for-each select="//eSubpackages/eClassifiers">
<xsl:for-each select="eStructuralFeatures/eAnnotations/details[@key='tabGroup'][not(@value=preceding::eStructuralFeatures/eAnnotations/details[@key='tabGroup']/@value)]">
<xsl:value-of select="@value"/>
</xsl:for-each>
</xsl:for-each>

Preceding is filtering the duplicates as expected using the above piece of code i.e it is able to output a "tabGroup" only when there is no ssame preceding "tabGroup". However, duplicates are no problem across "eClassifiers" but they are a problem only within a "eClassifier". Using the above approach, duplicates are being avoided even across "eClassifiers" i.e if a tabgroup is already present in one "eClassifier", it is filtered in the other "eClassifier" as well.

So, I have used the following to restrict the duplicate checking within an "eClassifier"

<xsl:for-each select="//eSubpackages/eClassifiers">
<xsl:variable name="classifier" select="@name"/>
<xsl:for-each select="eStructuralFeatures/eAnnotations/details[@key='tabGroup'][not(@value=preceding::eClassifiers[@name=$classifier]/eStructuralFeatures/eAnnotations/details[@key='tabGroup']/@value)]">
</xsl:for-each>
</xsl:for-each>

problem is that I get duplicates now. Not sure what is missing.


 
Old October 16th, 2008, 06:03 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

We've still no idea what your input XML looks like, what you want your output to look like, or the output you are currently getting.

/- Sam Judson : Wrox Technical Editor -/
 
Old October 16th, 2008, 06:25 AM
Authorized User
 
Join Date: Aug 2008
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default

 <eClassifiers xsi:type="ecore:EClass" name="BusinessProcess" eSuperTypes="platform:/plugin/com.ibm.team.repository.common/models/repository.ecore#//repository/SimpleItem">
  <eStructuralFeatures xsi:type="ecore:EReference" name="subProcess" upperBound="-1"
          eType="#//blueharmonypilot/SubProcess">
        <eAnnotations source="sednaProperty">
          <details key="inverse" value="processes"/>
          <details key="tabGroup" value="Process Details"/>
          <details key="tab" value="Sub Processes"/>
        </eAnnotations>
      </eStructuralFeatures>
      <eStructuralFeatures xsi:type="ecore:EReference" name="gap" upperBound="-1"
          eType="#//blueharmonypilot/Gap">
        <eAnnotations source="sednaProperty">
          <details key="inverse" value="processes"/>
          <details key="tabGroup" value="Design Considerations"/>
          <details key="tab" value="Gaps"/>
        </eAnnotations>
<eStructuralFeatures>
<eStructuralFeatures xsi:type="ecore:EReference" name="processModel" eType="#//blueharmonypilot/ProcessModel">
        <eAnnotations source="sednaProperty">
          <details key="tabGroup" value="Process Details"/>
          <details key="tab" value="Process Model"/>
        </eAnnotations>
</eStructuralFeatures>
</eClassifiers>

<eClassifiers xsi:type="ecore:EClass" name="SubProcess" eSuperTypes="platform:/plugin/com.ibm.team.repository.common/models/repository.ecore#//repository/SimpleItem">
  <eStructuralFeatures xsi:type="ecore:EReference" name="requirement" upperBound="-1"
          eType="#//blueharmonypilot/Requirement">
        <eAnnotations source="sednaProperty">
          <details key="inverse" value="subProcesses"/>
          <details key="tabGroup" value="Process Details"/>
          <details key="tab" value="Requirements"/>
        </eAnnotations>
      </eStructuralFeatures>

      <eStructuralFeatures xsi:type="ecore:EReference" name="gap" upperBound="-1"
          eType="#//blueharmonypilot/Gap">
        <eAnnotations source="sednaProperty">
          <details key="inverse" value="subProcesses"/>
          <details key="tabGroup" value="Design Considerations"/>
          <details key="tab" value="Gaps"/>
        </eAnnotations>
      </eStructuralFeatures>
<eClassifiers>

Above is the input xml, it has two "eClassifiers" and the values (@value) for tabGroups (@tabGroup) are "Process Details", "Design Considerations", "Process Details" (for the first eClassifier), "Process Details", Design Considerations" (for the second eClassifier). I would like to avoid duplicates only within an "eClassifier" not across. As I mentioned in the earlier post, usng the following, I get duplicates avoided across the eClassifiers.

<xsl:for-each select="//eSubpackages/eClassifiers">
<xsl:for-each select="eStructuralFeatures/eAnnotations/details[@key='tabGroup'][not(@value=preceding::eStructuralFeatures/eAnnotations/details[@key='tabGroup']/@value)]">
<xsl:value-of select="@value"/>
</xsl:for-each>
</xsl:for-each>

When I try to restict the duplicate checking using the following, I get duplicates infact.
<xsl:for-each select="//eSubpackages/eClassifiers">
<xsl:variable name="classifier" select="@name"/>
<xsl:for-each select="eStructuralFeatures/eAnnotations/details[@key='tabGroup'][not(@value=preceding::eClassifiers[@name=$classifier]/eStructuralFeatures/eAnnotations/details[@key='tabGroup']/@value)]">
</xsl:for-each>
</xsl:for-each>


 
Old October 16th, 2008, 06:39 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

>What I could not get right was duplicate checking within a particular subtree rather than the whole document

I think that for your particular data you should be using the preceding-sibling axis rather than the preceding axis. Something like

<xsl:for-each select="eStructuralFeatures[not(eAnnotations/details[@key='tabGroup']/@value=preceding-sibling::eStructuralFeatures/eAnnotations/details[@key='tabGroup']/@value)]/eAnnotations/details[@key='tabGroup']/@value)">

Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer's Reference
 
Old October 16th, 2008, 06:45 AM
Authorized User
 
Join Date: Aug 2008
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Precise outputs
--------------
When I use the following,

<xsl:for-each select="//eSubpackages/eClassifiers">
<xsl:variable name="classifier" select="@name"/>
<xsl:for-each select="eStructuralFeatures/eAnnotations/details[@key='tabGroup'][not(@value=preceding::eStructuralFeatures/eAnnotations/details[@key='tabGroup']/@value)]">


eClassifier name <xsl:value-of select="../../../@name"/>

current tab group <xsl:value-of select="@value"/>

</xsl:for-each>
</xsl:for-each>




output is
---------
eClassifier name BusinessProcess
current tab group Process Details

eClassifier name BusinessProcess
current tab group Design Considerations

When I use the following,

<xsl:for-each select="//eSubpackages/eClassifiers">
<xsl:variable name="classifier" select="@name"/>
<xsl:for-each select="eStructuralFeatures/eAnnotations/details[@key='tabGroup'][not(@value=preceding::eClassifiers[@name=$classifier]/eStructuralFeatures/eAnnotations/details[@key='tabGroup']/@value)]">


eClassifier name <xsl:value-of select="../../../@name"/>

current tab group <xsl:value-of select="@value"/>
</xsl:for-each>
</xsl:for-each>


the output is
-------------

eClassifier name BusinessProcess
current tab group Process Details


eClassifier name BusinessProcess
current tab group Design Considerations

eClassifier name BusinessProcess
current tab group Process Details

eClassifier name SubProcess
current tab group Process Details

eClassifier name SubProcess
current tab group Design Considerations



 
Old October 16th, 2008, 06:59 AM
Authorized User
 
Join Date: Aug 2008
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks Michael!






Similar Threads
Thread Thread Starter Forum Replies Last Post
Using preceding-sibling mcanne98 Infopath 0 September 11th, 2008 11:09 PM
Help with Preceding Franky83 XSLT 1 November 12th, 2007 06:20 PM
preceding-sibling jonesyp XSLT 2 November 22nd, 2005 12:29 PM
General Scoping Question cliffd64 VB.NET 2002/2003 Basics 2 June 9th, 2005 06:37 AM
preceding-sibling after sort rushman XSLT 3 January 18th, 2005 11:08 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.