2013-05-09 21 views
0

我在根據參數顯示我想要的XML標記時遇到問題。我對此很新。XSL - 基於PHP的參數顯示XML標記

XML實例:

<car name="Toyota"> 
    <model nr="123" yeardate="2010"> 
     <owner ssn="123456789" name="Tom"/> 
     <owned years="0" months="6"/> 
    </model> 
</car> 
<car name="Volvo"> 
    <model nr="222" yeardate="2009"> 
     <owner ssn="345364774" name="John"/> 
     <owned years="0" months="8"/> 
    </model> 
</car> 
<car name="Fiat"> 
    <model nr="333" yeardate="2010"> 
     <owned years="0" months="0"/> 
    </model> 
</car> 

的問題是,我希望能夠選擇顯示基於HTML表單我我的PHP文件中作出上車。所以,我在PHP中創建了一個表單,將POST的值發回給我的XSL文檔,現在我想根據此參數值顯示汽車。另外,請注意菲亞特車沒有車主。我可以在我的XSL文檔中獲得POST的值,但我不確定如何使用此參數。

我想象這是什麼轉向到: 比方說,豐田在形式choosen,

car name=Toyota 

model nr=123 yeardate=2010 

owner ssn=123456789 name=tom 

owned years=0 months=6 

我想包括標籤名稱以及所有屬性。

+0

你的代碼丟失了,也不清楚你的問題是什麼,現有的哪些答案沒有幫助你。列出它們並告訴什麼不適合你。 – hakre 2013-05-15 12:03:12

+0

[del-ref](http://stackoverflow.com/questions/16564345/xsl-parse-xml-with-paramter-from-php) – hakre 2013-05-15 14:38:32

回答

0

如果您使用PHP,也許您不需要XSL。看看SimpleXML

<?php 
$xmlString = '<root> 
    <car name="Toyota"> 
     <model nr="123" yeardate="2010"> 
      <owner ssn="123456789" name="Tom"/> 
      <owned years="0" months="6"/> 
     </model> 
    </car> 

    <car name="Fiat"> 
     <model nr="333" yeardate="2010"> 
      <owned years="0" months="0"/> 
     </model> 
    </car> 
</root>'; 

$xml = new SimpleXMLElement($xmlString); 

foreach ($xml->children() as $second_gen) { 
    if ((string) $second_gen['name'] == "Toyota") { 
     echo $second_gen->asXML(); 
    } 
} 
?>