[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: How to move processing instruction?

Subject: Re: How to move processing instruction?
From: "J. S. Rawat" <jrawat@xxxxxxxxxxxxxx>
Date: Mon, 16 Apr 2007 14:38:10 +0530
Re:  How to move processing instruction?
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][@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][@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

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.