<nodes>
<node>
<nodeFullName>JohnSmith</nodefullname>
<nodeName>John</nodeName>
</node>
<node>
<nodeFullName>JohnSecond</nodefullname>
<nodeName>John</nodeName>
</node>
</nodes>
我想返回与给定名称和姓氏匹配的节点(不区分大小写(
$XMLFILE.SelectNodes("//nodes/node[translate(nodeName,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz')=""$Name"" and starts-with(nodeFullName,concat($Name,$LastName) ]")
但是两个节点都返回了,第二个条件(之后和(没有被选中,我错过了什么?
在关闭过滤器之前,您不会关闭 Start-With 函数,而只是关闭 concact。该行末尾应为:
$Name,$LastName))]")
而不是:
$Name,$LastName)]")
恕我直言,事先在PowerShell中加入名字和姓氏可能更简单,而不是使用concact。
$FullName = $Name.tolower() + $LastName.tolower()
然后,您的开头可以读取:
starts-with(translate(nodeFullName,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz'),""$FullName"")]")
这是我测试的完整代码:
$XMLFILE = [XML]@"
<nodes>
<node>
<nodeFullName>JohnSmith</nodeFullName>
<nodeName>John</nodeName>
</node>
<node>
<nodeFullName>JohnSecond</nodeFullName>
<nodeName>John</nodeName>
</node>
</nodes>
"@
$Name = "John"
$LastName = "SMITH"
$FirstName = $Name.ToLower()
$FullName = $Fname + $LastName.ToLower()
$XMLFILE.SelectNodes("//nodes/node[translate(nodeName,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz')=""$FName"" and starts-with(translate(nodeFullName,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz'),""$FullName"")]")
这导致:
nodeFullName nodeName
------------ --------
JohnSmith John