-1

I've an issue in apply templates , consider my xml will be like this , enter code here

<card>
   <pre/>
<main>    
  <step1/>
  <step1/>
  <panels>
    <panel/>
    <panel/>
  </panels>
  <step1/>
<main> 
 </card>

Inside main all the step1 will be started with 1. and increment in further step.Now when the panel comes , it should take each panel as a step and it'll start as 3. , 4. next step1 will be 5.

problem is when if i apply templates for step1 in the mainfunc , it's applying for all the step1. so the step1 after the panel also will come in the first place . I want to apply temaplates for the step1 to 3rd step1. then apply panel and then apply the last step1.step1 counts are not always same , they differ.

currently ive something like this ,

<xsl:template match="mainfunc">
    <xsl:apply-templates select="step1"/>
    <xsl:if test="contains($wcType,'P')">
    <xsl:apply-templates select="panels"/>
    </xsl:if>
.....

how to modify to apply the templates in sequence order , also numbering the panel as 3.

Abyy
  • 31
  • 1
  • 9
  • Can you show the output you expect in this case, to make it clear about how the "numbering" should work. Thank you! – Tim C Mar 29 '17 at 08:46
  • numbering is fine .it ll be like for panels , for steps – Abyy Mar 29 '17 at 09:54
  • my only concern is how to call the templates in a sequence manner like step , and then next step and panel then step – Abyy Mar 29 '17 at 09:58
  • Sorry, but your question is completely unclear. We have no idea what you are trying to achieve. – Michael Kay Mar 29 '17 at 09:59
  • okie to put it very simple i ve a template minfunc , This will apply the step1 template for all the step1 in the xml , i want to apply only for the first 3 step1 , next it should apply for panel then to step1 again – Abyy Mar 29 '17 at 10:13

1 Answers1

0

This is a bit of a guess, as I am not entirely clear what you want to do, but I think what you could do is this...

<xsl:apply-templates select="step1|panels[contains($wcType,'P')]"/>

The | symbol is the union operator, and the union of nodes will be selected in document order. So, it will select the first step1, then the panels, then the next step1.

For example, this XSLT...

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    <xsl:output method="xml" indent="yes" />

    <xsl:variable name="wcType" select="'Pie'" />

    <xsl:template match="main">
        <xsl:apply-templates select="step1|panels[contains($wcType,'P')]"/>
    </xsl:template>

    <xsl:template match="step1|panel">
        <xsl:copy>
            <xsl:number count="step1|panel" level="any" />
        </xsl:copy>
    </xsl:template>
</xsl:stylesheet>

When applied to this XML...

<card>
  <main>    
    <step1/>
    <step1/>
    <panels>
      <panel/>
      <panel/>
    </panels>
    <step1/>
  </main> 
</card>

The following is output

<step1>1</step1>
<step1>2</step1>
  <panel>3</panel>
  <panel>4</panel>
<step1>5</step1> 
Tim C
  • 70,053
  • 14
  • 74
  • 93
  • in step1 template for the numbering i've given like , , in the panel template i ve given like this , , now the sequence is fine its calling the 1. step1 2. step1 1.panel 2.panel 3.step1 , numbering is not proper now pleaese help panel will be in panels parent tag , so i ve used , to count the panel – Abyy Mar 29 '17 at 11:01
  • If you want help with the numbering, you should really edit your question to show the expected output with the numbering, as code is really hard to read in comments. Thanks. – Tim C Mar 29 '17 at 11:33
  • sure Tim, I 'm trying some logic for numbering , will come back soon tim – Abyy Mar 29 '17 at 12:17