<a>
<b/>
<b/>
<c/>
</a>
我想找出我正在解析的当前元素的计数 当我的节点在当前元素中时,我也不知道元素名称。
我试过了:
<xsl:for-each select="a">
<counter localName="{local-name()}" count="{count(node()/*)}"/>
</xsl:for-each>
我希望输出:
<counter localName="b" count="2"/>
<counter localName="b" count="2"/>
<counter localName="c" count="1"/>
这给出了错误的输出我如何实现它?
答案 0 :(得分:1)
我猜你想做:
@ECHO OFF
setlocal enabledelayedexpansion
SET Location_Folder=V:
SET Destination_folder=V:\Nonimportable
SET Check_file_validation=V:\Nonimportable\result.txt
SET Excluded_folder=Nonimportable
set "lineNr=12"
For /f "tokens=*" %%O in ('dir /b /a:d "%Location_Folder%"') do (
set filename=%%O
call D:\somefolder\otherfolder\batscriptname.bat !filename!
set Validation=
echo !filename!| FINDSTR /i /c:"%Excluded_folder%" >NUL
IF ERRORLEVEL 1 (
for /F "skip=12 delims=" %%a in (%Check_file_validation%) do if not defined Validation (
set Validation=%%a
call :valid
)
) else (
echo This folder name is excluded: !filename!
)
)
goto Finish
:valid
echo !Validation!| FINDSTR /c:"1" >NUL
if ERRORLEVEL 1 (
set Folder_path=%Location_Folder%\!filename!
set New_Folder_path=%Destination_folder%\!filename!
mkdir "!New_Folder_path!"
echo D | xcopy /o /y /q /s /v "!Folder_path!" "!New_Folder_path!"
rmdir /s /q "!Folder_path!"
) else (
echo Folder is valid !filename!
goto Finish
)
:Finish
exit /b
这将返回:
<xsl:template match="/a">
<root>
<xsl:for-each select="*">
<counter localName="{local-name()}" count="{count(../*[local-name()=local-name(current())])}"/>
</xsl:for-each>
</root>
</xsl:template>
请注意,使用<root>
<counter localName="b" count="2"/>
<counter localName="b" count="2"/>
<counter localName="c" count="1"/>
</root>
您有意忽略命名空间。因此,如果输入恰好是:
local-name()
尽管显然两个<a>
<b/>
<ns1:b xmlns:b="http://example.com/b"/>
<c/>
</a>
节点一起计算除了巧合之外没有任何共同之处。