xsl中的单独条目,用于在PHP中进一步传递和更改

时间:2018-05-08 08:16:10

标签: javascript php xslt

<xsl:for-each select="items/item[itemStatus='in_progress']">
        <div style="background-color: #00ccff; border: 2px solid black; padding-bottom: 10px; margin-bottom: 15px; width: 500px; padding-left: 20px">
        <p><b>Item ID: </b><xsl:value-of select="./itemID" /></p>
        <p><b>Item Name: </b><xsl:value-of select="./itemName" /></p>
        <p><b>Category: </b><xsl:value-of select="./category" /></p>
        <p><b>Buy It Now Price: </b><xsl:value-of select="./BINPrice" /></p>
        <p><b>Bid Price: </b><xsl:value-of select="./startPrice" /></p>
        <p><b>Duration: </b><xsl:value-of select="./duration" /></p>
        <button type="button" style="margin-right: 10px" onclick="updateXML()">Place Bid</button>
        <button type="button" onclick="">Buy It Now</button>
        </div>
</xsl:for-each>

使用上面的代码格式化xml后,得到以下结果: click

一切都很酷。下一步我想通过使用prompt()输入来更改“出价”,将其传递给php并将.xml中的旧“出价”更新为来自prompt()的新出价。 php中的代码:

<?php
    // preparing xml file
    session_start();
    $xmlFile = "auction.xml";
    $doc = new DOMDocument("1.0");
    $doc->preserveWhiteSpace = false;
    $doc->formatOutput = true;

     //update details
    $customerID = $_SESSION['use'];
    $newBid = $_REQUEST['newBid'];

    $unique = true;



    if (($unique == true))
    {
        $xmlFile = "auction.xml";
        $doc = new DOMDocument("1.0");
        $doc->preserveWhiteSpace = false;
        $doc->formatOutput = true;
        $doc->load($xmlFile);
        $thedocument = $doc->documentElement;

        $item = $doc->getElementsByTagName("item");
        $items = $doc->getElementsByTagName("items")->item(0);

          // checking each customer in xml file
         foreach($item as $node)
        {
            $XMLcustomerID = $node->getElementsByTagName("customerID");
            $XMLcustomerIDValue = $XMLcustomerID->item(0)->nodeValue;

            $XMLstartPrice = $node->getElementsByTagName("startPrice");
            $XMLstartPriceValue = $XMLstartPrice->item(0)->nodeValue;

            $XMLcustomerID->item(0)->nodeValue = $customerID;
            $XMLstartPrice->item(0)->nodeValue = $newBid;
            $saveXML =  $doc->save($xmlFile);
        }
    }
?>

您可能已经了解它会更改xml中所有条目的“出价”值,但不会更改我点击“放置出价”的值。 我的代码应该更改哪些内容才能更改特定条目的出价价值?

0 个答案:

没有答案