xsl-list
[Top] [All Lists]

Re: [xsl] How to move processing instruction?

2007-04-16 03:05:11
Wow... you changed the data below, where it was supposed to be your original post... when you said to check again I looked again to your initial post. Well, anyway, you changed the input but that still does not give the output as you do not generate the body element...

I'm starting to guess on your requirements. You want to create a document with the root element body and place for each div in the input a div in the output that contains processing instructions. Those processing instructions are either the immediate preceding siblings of the div element or the immediate preceding siblings of the parent element of the div element.

In that case you can have something like below:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>

  <xsl:template match="publication">
    <body>
      <xsl:apply-templates/>
    </body>
  </xsl:template>

  <xsl:template match="div">
    <div>
      <xsl:choose>
<xsl:when test="preceding-sibling::node()[self::processing-instruction()]">
          <xsl:copy-of

select="preceding-sibling::processing-instruction()[generate-id(following-sibling::*[1])=generate-id(current())]"
          />
        </xsl:when>
        <xsl:otherwise>
          <xsl:copy-of

select="../preceding-sibling::processing-instruction()[generate-id(following-sibling::*[1])=generate-id(current()/..)]"
          />
        </xsl:otherwise>
      </xsl:choose>
    </div>
  </xsl:template>

</xsl:stylesheet>


Add your type attribute processing rule as desired.

Regards,
George
---------------------------------------------------------------------
George Cristian Bina
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com


J. S. Rawat wrote:
Please you check your input and cross-check it with my INPUT as shown below


At 12:29 PM 4/16/2007 +0300, you wrote:
Double checked...

What I get as output is

<?xml version="1.0" encoding="UTF-8"?>



    <div type="chapter"/>


    <div type="chapter"><?page x?><?page 1?></div>


What you say you are getting as output is:
<body>
<div type="chapter"/>
<div type="chapter">
<?page 3?>
<?page 4?>
</div>
</body>

It is clear that the code you posted or even both the code and your input file are different in your test than what you posted...

Regards,
George
---------------------------------------------------------------------
George Cristian Bina
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com


J. S. Rawat wrote:
Please check the requirement once again!!!
At 12:02 PM 4/16/2007 +0300, you wrote:

Hi,

You are not showing your XSLT code, that does not produce the result you are saying it produces... I also do not understand the logic of the transformation, you have page 1 and page x and that produces in the output page 3 and page 4...

My advise is to look again into your files and try posting again with the correct samples.

Regards,
George
---------------------------------------------------------------------
George Cristian Bina
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com


J. S. Rawat wrote:
Hi
I have done all the hit and try and stuck once again!!! Please help how to move processing instruction which are sibling of <pub-div>>


XSL
<xsl:template match="processing-instruction('page')" mode="move">
<xsl:processing-instruction name="page"><xsl:value-of select="."/></xsl:processing-instruction>
</xsl:template>
<xsl:template match="div">
<div>
<xsl:attribute name="type">
<xsl:choose>
<xsl:when test="@type='part'">part</xsl:when>
<xsl:otherwise>chapter</xsl:otherwise>
</xsl:choose>
</xsl:attribute>
<xsl:if test="preceding-sibling::processing-instruction('page')">
<xsl:apply-templates select="preceding-sibling::processing-instruction('page')[following-sibling::div[1][(_at_)id = current()/@id]]" mode="move" />
</xsl:if>
</div>
</xsl:template>

INPUT
<publication>
<?page 1?>
<?page 2?>
<pub-div type="body" id="C1">
<div type="chapter" id="C2">
...
</div>
<?page 3?>
<?page 4?>
<div type="chapter" id="C3">
...
</div>
</pub-div>
</publication>


OUTPUT
<body>
<div type="chapter"/>
<div type="chapter">
<?page 3?>
<?page 4?>
</div>
</body>


REQUIRED OUTPUT
<body>
<div type="chapter">
<?page 1?>
<?page 2?>
</div>
<div type="chapter">
<?page 3?>
<?page 4?>
</div>
</body>
thanks
JSR

Great!!! George thank a lot!!!

At 12:00 PM 4/12/2007 +0300, you wrote:
Then change the templates as below:
* match processing instructions that have the first following sibling element that contains div and do not copy them * match div and copy the processing instructions that are preceding siblings of its parent element


<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>

  <xsl:template match="node() | @*">
    <xsl:copy>
      <xsl:apply-templates select="node() | @*"/>
    </xsl:copy>
  </xsl:template>

<xsl:template match="processing-instruction()[following-sibling::*[1]/div]"/>

  <xsl:template match="div">
    <xsl:copy>
      <xsl:apply-templates select="@*"/>
<xsl:copy-of select="../preceding-sibling::processing-instruction()"/>
      <xsl:apply-templates select="node()"/>
    </xsl:copy>
  </xsl:template>

</xsl:stylesheet>

Regards,
George
---------------------------------------------------------------------
George Cristian Bina
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com


J. S. Rawat wrote:
Dear George you understand right but I need to move the processing instruction (<? page x?><? page x?>) which are just before of parent of "div". In other words we can say that: How to copy the sibling (processing instruction) of parent of "div"
thanks
...JSR

At 10:39 AM 4/12/2007 +0300, you wrote:
Hi,

It is not clear what the logic of the transformation is so I will just assume that what you want is to move the processing instructions that are in the source before the root element inside the div element. In that case you can start with the recursive copy template and add a couple of rules to avoid copying PIs that are children of the document node and to copy then inside the div element:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>

  <xsl:template match="node() | @*">
    <xsl:copy>
      <xsl:apply-templates select="node() | @*"/>
    </xsl:copy>
  </xsl:template>

  <xsl:template match="/">
    <xsl:apply-templates select="*"/>
  </xsl:template>

  <xsl:template match="div">
    <xsl:copy>
      <xsl:apply-templates select="@*"/>
      <xsl:apply-templates select="/processing-instruction()"/>
      <xsl:apply-templates select="node()"/>
    </xsl:copy>
  </xsl:template>

</xsl:stylesheet>

Regards,
George
---------------------------------------------------------------------
George Cristian Bina
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com


J. S. Rawat wrote:
Dear Expert(s):
Could anybody help me to get the following results:
INPUT:
<?page x?>
<?page 1?>
<pub-div type="body" id="C7967-10">
<div type="chapter" id="C7967-11">
<div-meta>
<lrh>MOVIES AND THE REAGAN PRESIDENCY: SUCCESS AND ETHICS</lrh>
<rrh>DEFINING REAGAN-ERA HOLLYWOOD</rrh>
</div-meta>
<label>Chapter 1</label>
<head>Defining Reagan-Era Hollywood</head>
<p>xxxx</p>
</div>
</pub-div>
OUTPUT:
<pub-div type="body" id="C7967-10">
<div type="chapter" id="C7967-11">
<?page x?>
<?page 1?>
<div-meta>
<lrh>MOVIES AND THE REAGAN PRESIDENCY: SUCCESS AND ETHICS</lrh>
<rrh>DEFINING REAGAN-ERA HOLLYWOOD</rrh>
</div-meta>
<label>Chapter 1</label>
<head>Defining Reagan-Era Hollywood</head>
<p>xxxx</p>
</div>
</pub-div>
XSL:
<xsl:template match="div">
<div>
<xsl:if test="preceding-sibling::processing-instruction('page')">
<xsl:apply-templates select="preceding-sibling::processing-instruction('page')[following-sibling::div[1][(_at_)id = current()/@id]]"/>
</xsl:if>
<xsl:apply-templates select="*[not(self::div-meta or self::label or self::head or self::subhead or self::author)]"/>
</xsl:template>
thanks in advance
...Joga S. Rawat

--~------------------------------------------------------------------ XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

--~------------------------------------------------------------------ XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--




--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--