Altova Mailing List Archives>Archive Index >microsoft.public.xsl Archive Home >Recent entries >Thread Prev - Re: counting complex patterns [Thread Next] Re: counting complex patternsTo: 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.
| ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
