Hi Stefan!
Before suggesting a concrete solution, it would help to understand what you’re ultimately trying to achieve.
For example:
Why do you need to stop after the third IRSI?
What will the current number be used for elsewhere in the script?
Is the goal to limit output, apply special handling to certain items, or something else?
If you can describe the end result you want, there’s a good chance this can be solved.
Best regards,
SystemWeaver Support
I tried to use some common SID's to reduce work without showing to much that is VBG speciffic.
Since VBG have implementeqd the Systemite BPSE model with some minor additions, templates etc needs to be updated accordingly.
So this specification template is using a baseline to check that selected component is part of baseline and it's component list.
What I'm trying to do is to check different ItemTemplates that should behave different depending on it's content.
If a SW ECU (SID=AREU) contains several parts of type ARSC and one of theese contains a part VP0080 (Diagnostics), the if this item have 2 or more lists it's a standar Diagnostic items that describes the diagnostics behaviour.
But if a SW ECU (SID=AREU) contains only one part of type ARSC and then the item ARCP only contains 1 part and it's part VP0080 (Diagnostics), the if this item only have one lists and it's a DID List, then it's the default calibration setting to be used when producing the ECU.
I've made an extraction of the XML definition and attached it.
I hope that this might explain it a litle more.
BR
/Stefan

Hi Stefan,
If I understand you correctly, you want to inspect the metamodel/data (part SIDs) and, depending on which types of part SIDs are used, call different templates—each with its own logic. If that’s the case, the code below shows an example of how to do it.
For the checks (filters), you can either keep using the filter approach you’ve implemented, or use Path Language—both options work.
Using PathLanguage
<ForEach select="/IRRS">
<Choose>
<When test="/ARCW and not /VP0080">
<ApplyTemplate name="template_A"/>
</When>
<When test="/VP0080 and not /ARCW ">
<ApplyTemplate name="template_B"/>
</When>
<When test="/VP0080 ">
<ApplyTemplate name="template_C"/>
</When>
<Otherwise>
<ApplyTemplate name="template_D"/>
</Otherwise>
</Choose>
</ForEach>
<!--Different template-->
<Template name="template_A">
<Section title="#{Name}">
<!-- do something here-->
</Section>
</Template>
<Template name="template_B">
<Section title="#{Name}">
<!-- do something here-->
</Section>
</Template>
<Template name="template_C">
<Section title="#{Name}">
<!-- do something here-->
</Section>
</Template>
<Template name="template_D">
<Section title="#{Name}">
<!-- do something here-->
</Section>
</Template>
Using filters
<Filter name="Functional">
<And>
<ItemHasPartOfType sid="ARCW"/>
<Not>
<ItemHasPartOfType sid="VP0080"/>
</Not>
</And>
</Filter>
<Filter name="Diagnostics">
<And>
<ItemHasPartOfType sid="VP0080"/>
<Not>
<ItemHasPartOfType sid="ARCW"/>
</Not>
</And>
</Filter>
<Filter name="Calibration">
<ItemHasPartOfType sid="VP0080"/>
</Filter>
<ForEach select="/IRRS">
<Choose>
<When filter="Functional">
<ApplyTemplate name="template_A"/>
</When>
<When filter="Diagnostics">
<ApplyTemplate name="template_B"/>
</When>
<When filter="Calibration">
<ApplyTemplate name="template_C"/>
</When>
<Otherwise>
<ApplyTemplate name="template_D"/>
</Otherwise>
</Choose>
</ForEach>
<!--Different template-->
<Template name="template_A">
<Section title="#{Name}">
<!-- do something here-->
</Section>
</Template>
<Template name="template_B">
<Section title="#{Name}">
<!-- do something here-->
</Section>
</Template>
<Template name="template_C">
<Section title="#{Name}">
<!-- do something here-->
</Section>
</Template>
<Template name="template_D">
<Section title="#{Name}">
<!-- do something here-->
</Section>
</Template>
Thanks Bashar for the answer.
I've already evaluated these suggestions.
Since the issue was to handle the item ARCP (CompositionSWComponent) differently depending on it's parts and also number of parts type VP0080.
Already on item AREU (Software ECU) I want to evaluate how may parts ARSC there are.
So I came up to use these solutions so far. But it needs some improvement to be bullet proof.
<ItemTemplate type="AREU"> <!-- Software ECU -->
<ForEachPart type="ARSC" sort="PartNo">
<If test=".[PartNo=1] and /VP0080=[]">
<DefObj>
<If filter="Functional" test="$Composition='Application'">
<Section title = "Functional Requirements">
<ApplyItemTemplates/>
</Section>
</If>
</DefObj>
</If>
<If filter="Diagnostics" test=".[PartNo!=1]">
<DefObj>
<Section title="Diagnostics">
<ForEachPart type="VP0080" sort="PartNo"> <!-- Diagnostics-->
<DefObj>
<ApplyItemTemplates/>
</DefObj>
</ForEachPart>
</Section>
</DefObj>
</If>
<If filter="Calibration" test="$Composition='Calibration'">
<Section title = "Calibration settings">
<DefObj>
<ApplyItemTemplates/>
</DefObj>
</Section>
</If>
</ForEachPart>
</ItemTemplate>
Edvardsson, Stefan
I would like to be able to count how many times a ForEach have looped and brake after say the third time out of 5 possible times.
In addition I would be able to forward the current number in an variable to be used elsewhere in the script.
Example:
A section item of SID='SSSE' have 5 part of type IRSI.
Using /IRSE.Count the answer is 5.
But is it possible to count and keep track of how many parts are passed in a ForEach select="/IRSI"and maybe also store that in a variable?
Thanks
/Stefan