Question: Hello there i am trying to build one database for a online store my problem definition is 
an order can contains many items with different delivery dates **for example 1 book will take 2 days to deliver another take 4-5 days to deliver.**

I have a Product table which contains product delivery time like 2-3 working days or 4-5 working days 

In my delivery table how am i going to depict this because it contains 1 order id i can show the user the upper limit time like 5 days for the delivery but how can i show the back end user 2 different order timings and status of 1 order 

How can i show them into my delivery table as they are one order but having different delivery times..

Answer: 
It turns out that just calling `xmlNewDocPI` is not enough. It creates the processing instruction node and somehow associates it to the document but **it doesn't actually attach it to the document**.

For that purpose some of the `xmlAdd*` functions must be called and, since I need the PI to be included right below the XML declaration and not nested within the documents root node, I had to use the following:

```c
xmlAddPrevSibling(Doc->get_root_node()->cobj(), PINode);

```

It looks kind of hackish but works. So the full snippet for the working code gets like this:

```c
xmlpp::Document* Doc = Parser->get_document();

// Set processing instruction for stylesheet
const xmlNodePtr PINode = xmlNewDocPI(
    Doc->cobj(),
    reinterpret_cast<xmlChar*>("xml-stylesheet"),
    reinterpret_cast<xmlChar*>("href=\"../stylesheet.xslt\" type=\"text/xsl\"")
);

if (PINode != NULL) {
    xmlAddPrevSibling(Doc->get_root_node()->cobj(), PINode);
}

Doc->write_to_file_formatted("mydoc.xml", "utf-8");

```
**Adding a processing instruction to an XML document can be done in pure XSLT**:

```
<xsl:stylesheet version="1.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:output omit-xml-declaration="yes" indent="yes"/>
 <xsl:strip-space elements="*"/>

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

 <xsl:template match="/">
  <xsl:processing-instruction name="xml-stylesheet">
    <xsl:text>href="../stylesheet.xslt" type="text/xsl"</xsl:text>
  </xsl:processing-instruction>
  <xsl:text>&#xA;</xsl:text>
  <xsl:apply-templates/>
 </xsl:template>
</xsl:stylesheet>

```

when this transformation is applied to any XML document, such as the one below:

```
<nums>
  <num>01</num>
  <num>02</num>
  <num>03</num>
  <num>04</num>
  <num>05</num>
  <num>06</num>
  <num>07</num>
  <num>08</num>
  <num>09</num>
  <num>10</num>
</nums>

```

**the wanted result is produced**:

```
<?xml-stylesheet href="../stylesheet.xslt" type="text/xsl"?>
<nums>
   <num>01</num>
   <num>02</num>
   <num>03</num>
   <num>04</num>
   <num>05</num>
   <num>06</num>
   <num>07</num>
   <num>08</num>
   <num>09</num>
   <num>10</num>
</nums>

```