0

This is my first time working with XSLT files. I have to change a report using a XSL file and I have the following problem:

  1. I have 3 variables which have to match to identify my right XML tag
  2. One of these variable is defined in a sub-sub-tag
  3. My result is located in the first sub-tag

To choose the right attribute, I use the following XSL code:

<xsl:for-each select="MSMResults/MSMVarContribs/Contrib">
  <xsl:variable name="PrtAsmType"><xsl:value-of select="@PrtAsmType"/></xsl:variable> 
  <xsl:variable name="CadName"><xsl:value-of select="@PrtAsmCadName"/></xsl:variable> 
  <xsl:variable name="ContribType"><xsl:value-of select="@Type"/></xsl:variable> 
  <xsl:variable name="ID"><xsl:value-of select="@ID"/></xsl:variable>
  <xsl:value-of select="/CETOLReport/PrtAsm[@Type=$PrtAsmType and @CadName=$CadName and /Feature/SizeDimension/Variable/@ID=$ID]//SizeDimension/@Note"/>

This is the XML file (shortened):

<CETOLReport>   
<PrtAsm Type="PART" CadName="PRT0001" Name="PRT0001">
  <VariationRule>
  <Alerts Count="0"/>
  <Feature>
  ...
  </Feature>
  ...
  <Feature Note="">
     <Alerts Count="0"/>
     <SizeDimension Note="PRT001&#xa;dim.# 01">
        <Tolerance Lower="0.1" Upper="0.2"/>
        <VariationRule ControlSkew="TRUE"/>
        ...
        <Variable Note="" Nominal="9" ID="12">
           <Distribution Mean="9.149999999999999"/>
           <Alerts Count="0"/>
        </Variable>
     </SizeDimension>
     <Dimension>
     ...
     </Dimension>
     <Dimension>
     ...
     </Dimension>
  </Feature>
  <Feature>
  ...
  </Feature>
</PrtAsm>
</CETOLReport>

Summed up:

I have to match

  • the attribute Type in <PrtAsm>
  • the attribute CadName in <PrtAsm>
  • the attribute ID in <PrtAsm/Feature/SizeDimension/Variable>

and as an output I want

  • the attribute Note in <PrtAsm/Feature/SizeDimension>

What do I have to change in <xsl:value-of select="/CETOLReport/PrtAsm[@Type=$PrtAsmType and @CadName=$CadName and /Feature/SizeDimension/Variable/@ID=$ID]//SizeDimension/@Note"/> to get the right answer?

  • Is it just a copy error in your question? you didn't close the tag while defining the variables. See for example: – Loic Mouchard Jun 02 '16 at 11:45
  • Hi Loic, yes that is just a copy error. I will change it in my question, thank you! – Lars Fischheiter Jun 02 '16 at 12:05
  • Please do not add "thank you" as an answer. Instead, you should accept the answer that solved your problem. When you have enough reputation, you can also [upvote helpful answers](http://stackoverflow.com/help/privileges/vote-up) or [award a bounty to helpful answers](http://stackoverflow.com/help/bounty). – elixenide Jun 06 '16 at 15:49

2 Answers2

0

I would try:

<xsl:value-of select="/CETOLReport/PrtAsm[@Type=$PrtAsmType and @CadName=$CadName and Feature/SizeDimension/Variable/@ID=$ID]/Feature/SizeDimension[1]/@Note"/>
Loic Mouchard
  • 1,121
  • 7
  • 22
0

Try this....

<xsl:value-of select="/CETOLReport
                      /PrtAsm[@Type=$PrtAsmType and @CadName=$CadName]
                      /Feature/SizeDimension[Variable/@ID=$ID]/@Note"/>
Tim C
  • 70,053
  • 14
  • 74
  • 93