我有一个包含以下信息的 csv 文件
ParentID,DivID,DataElement,Content,Class
Dash_Reg,Summer_Active,Classes.Active,Active Classes:,class1
Dash_Reg,Summer_Active,Classes.Inactive,Inactive Classes:,class1
Summer_Active,Pass_classes,Classes.passed,Classes Passed:,class1
Summer_Active,Failed_classes,failed.classes,Failed Classes:,class1
Dash_FinAid,Award_Amount,Amount.Awarded,Amount Awarded:,class1
Award_Amount,Refund_Status,Refund.Status,Refund Status:,class1
这个想法是让 PowerShell 遍历 csv 并从中创建正确的 HTML 代码,以创建正确的嵌套。这应该创建以下 HTML 代码:
<div id="Dash_Reg>
<div id="Summer_Active">
<p>Active Classes: <span id="Classes.Active"></span></p>
<p>Inactive Classes: <span id="Classes.Inactive"></span></p>
<div id="Pass_classes">
<p>Passed Classes: <span id="Classes.passed"></span></p>
</div>
<div id="Failed_Classes>
<p>Failed Classes: <span id="failed.classes"></span></p>
</div>
</div>
</div>
<div id="Dash_FinAid>
<div id="Award_Amount>
<p>Amount Awarded: <span id="Amount.Awarded></span></p>
<div id="Refund_Status>
<p>Refund Status: <span id="Refund.Status"></span></p>
</div>
</div>
我写的脚本如下:
import-csv values.csv|group-object -property ParentID|export-csv test.csv
new-item paws.html -type file
$variableset = import-csv test.csv
foreach ($row in $variableset){
new-item (($row.Name) + ".html") -type file
add-content (($row.Name) + ".html") ("<div id='" + ($row.Name) + "'>")
}
$csv = import-csv values.csv
foreach ($row in $csv){
$dataelement = $row.DataElement
$DivID = $row.DivID
$content = $row.content
$parentid = $row.ParentID
$class = $row.Class
add-content (($parentid) + ".html") ("<div id='" + ($DivID) + "'>")
add-content (($parentid) + ".html") ("<div class='" + ($class) + "'>" + ($content) +<span id='" + ($dataelement) + "'></span></div></div>")
}
add-content paws.html "<html><head><title>PAWS</title><link href='http://rsprodscd.gsu.edu/student-dashboard/assets/css/bootstrap.css' rel='stylesheet'></head><body>"
foreach ($row in $variableset){
$name = $row.Name
add-content (($row.Name) + ".html") "</div>"
get-content (($row.Name) + ".html")|add-content paws.html
rm (($row.Name) + ".html")
}
add-content paws.html "</div>"
add-content paws.html "</body>"
add-content paws.html "</html>"
这将产生以下 HTML 代码:
<html><head><title>PAWS</title><link href='http://rsprodscd.gsu.edu/student-dashboard/assets/css/bootstrap.css' rel='stylesheet'></head><body>
<div id='Dash_Reg'>
<div id='Summer_Active'>
<div class='class1'>Active Classes:<span id='Classes.Active'></span></div></div>
<div id='Summer_Active'>
<div class='class1'>Inactive Classes:<span id='Classes.Inactive'></span></div></div>
</div>
<div id='Summer_Active'>
<div id='Pass_classes'>
<div class='class1'>Classes Passed:<span id='Classes.passed'></span></div></div>
<div id='Failed_classes'>
<div class='class1'>Failed Classes:<span id='failed.classes'></span></div></div>
</div>
<div id='Dash_FinAid'>
<div id='Award_Amount'>
<div class='class1'>Amount Awarded:<span id='Amount.Awarded'></span></div></div>
</div>
<div id='Award_Amount'>
<div id='Refund_Status'>
<div class='class1'>Refund Status:<span id='Refund.Status'></span></div></div>
</div>
</div>
</body>
</html>
我想要做的是检查 ParentID 是否作为 DivID 在 CSV 中存在,以及它是否确实将该 HTML 代码嵌套在拱形父 ID 下。让我知道这是否有意义。