Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: counting complex patterns

From: "Dimitre Novatchev" <dimitren@---.---.-->
To: NULL
Date: 6/16/2005 6:48:00 AM
This would be easy to solve once the problem is defined precisely.

At the moment it isn't.

For example:

> I want to count the number of classes that reference a set of sources,
> e.g., "XYZ and VWX", via <source-assoc/> or <reqt-assoc/> tags
> ****** Desired output for XYZ and VWX *******
> 5
> *****************************

No. The answer is 0. There isn't even a single class that references both 
XYZ and VWX.

Probably you meant "XYZ or VWX"


For now -- just guessing -- what you most probably want is something like 
this:

count(/*/*/class
                [descendant::*
                     [ @source = 'XYZ'
                    or @source='VWX'
                    or starts-with(@reqt, 'XYZ-')
                    or starts-with(@reqt, 'VWX-')
                      ]
                 ]
         )


which in your example eveluates to 5.

Constructing such an expression is trivial with the XPath Visualizer (took 
less than a minute).


Cheers,
Dimitre Novatchev.

<drs58@m...> wrote in message 
news:1118786787.715013.15570@g......
Same as before but with a root node 'model':


****** Sample XML *******
<model>
  <source id="VWX" description="This is VWX"/>
  <source id="WXY" description="This is WXY"/>
  <source id="XYZ" description="This is XYZ"/>
  <reqt id="VWX-01" description="This is a requirement identified
within
  source VWX"/>
  <reqt id="XYZ-01" description="This is a requirement identified
within
  source XYZ"/>
  <reqt id="XYZ-02" description="This is another requirement identified

  within source XYZ"/>
  <package name = "pkg01">
    <class name="ABC">
      <source-assoc source="XYZ"/>
    </class>
    <class name="BCD">
      <reqt-assoc reqt="XYZ-01"/>
    </class>
    <class name="CDE">
      <source-assoc source="XYZ"/>
      <reqt-assoc reqt="XYZ-01"/>
      <reqt-assoc reqt="XYZ-02"/>
    </class>
    <class name="DEF">
      <reqt-assoc reqt="VWX-01"/>
    </class>
    <class name="EFG">
      <reqt-assoc reqt="XYZ-02"/>
    </class>
    <class name="FGH">
      <source-assoc source="WXY"/>
    </class>
  </package>
</model>
*****************************


I want to count the number of classes that reference a set of sources,
e.g., "XYZ and VWX", via <source-assoc/> or <reqt-assoc/> tags
****** Desired output for XYZ and VWX *******
5
*****************************


My approach is to:
1) construct a variable with all source document id's concatenated and
delimited by '*', e.g.,
  <xsl:variable name="source-ids">*VWX*WXY*XYZ­*</xsl:variable>


2) for each class, construct a variable by iterating through the
classes and adding a character, e.g., 'X',
   every time I find a one with an appropriate <source-assoc> or
<reqt-assoc/> tag, e.g.,
  <xsl:variable name="related-classes">
     <xsl:for-each select="package/class">
         <


xsl:if test=".//source-assoc[contains­($source-ids, '*' +
@source + '*')] | .//reqt-assoc[contains($source­-ids, '*' +
substring-before(@reqt, '-') + '*')]">X</xsl:if>
     </xsl:for-each>
  </xsl


:variable>
  NOTE: I want to include the delimiter in the contains function
parameter to ensure that the match is not based on a substring within a

source id
  NOTE: The <source-assoc/> and <reqt-assoc/> tags might actually also
be included within elements contained within classes.

3) display string-length($related-classes­)


Problem: I don't believe "'*' + @source + '*'" is being processed
correctly within the contains function.




transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent