도구 (VSS 데이터베이스에서보고)의 보고서로 큰 (200k 줄) XML 파일이 있습니다. 다음과 같은 많은 <file>
요소 로 구성됩니다 .
<file>
<name>file.bat</name>
<version>111</version>
<checkedout>No</checkedout>
<binary>Text</binary>
<vss_path>$/Code/file.bat</vss_path>
<original_path>C:\code\file.bat</original_path>
<action>Labeled '1.2.3.4'</action>
<date>27/09/2013 09:08:00</date>
<comment></comment>
<label>1.2.3.4</label>
<label_comment></label_comment>
<user>John</user>
<shared_links>
<shared_link>$/Beta_1</shared_link>
<shared_link>$/Branches/New_Feature</shared_link>
</shared_links>
</file>
내가 찾으려 만<file>
적어도 하나가이 요소 <shared_link>
로 시작하는 / "$ / 베타"접두사를.
이상적인 세계에서 일치하는 각 요소에 대해 원하는 것은 <name>
, <vss_path>
및 (일치하는) <shared_link>
부분이지만 그게 정확히 중요하지는 않습니다.
나는 XSLT / XPATH에 정통하지 않지만 그들이 이런 일을 할 수 있다고 믿습니까?
이 XSLT 스타일 시트 :
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes" omit-xml-declaration="yes"/>
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="root">
<xsl:copy>
<xsl:apply-templates select="file[shared_links[shared_link[starts-with(., '$/Beta')]]]"/>
</xsl:copy>
</xsl:template>
<xsl:template match="file">
<xsl:copy>
<xsl:apply-templates select="name | vss_path | shared_links"/>
</xsl:copy>
</xsl:template>
<xsl:template match="shared_links">
<xsl:copy>
<xsl:apply-templates select="shared_link[starts-with(., '$/Beta')]"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
이 입력 XML에 적용 할 때 (사용자의 것과 같지만 일치하지 않는 추가 파일이 추가됨) :
<root>
<file>
<name>file.bat</name>
<version>111</version>
<checkedout>No</checkedout>
<binary>Text</binary>
<vss_path>$/Code/file.bat</vss_path>
<original_path>C:\code\file.bat</original_path>
<action>Labeled '1.2.3.4'</action>
<date>27/09/2013 09:08:00</date>
<comment></comment>
<label>1.2.3.4</label>
<label_comment></label_comment>
<user>John</user>
<shared_links>
<shared_link>$/Alpha_1</shared_link>
<shared_link>$/Branches/New_Feature</shared_link>
</shared_links>
</file>
<file>
<name>file.bat</name>
<version>111</version>
<checkedout>No</checkedout>
<binary>Text</binary>
<vss_path>$/Code/file.bat</vss_path>
<original_path>C:\code\file.bat</original_path>
<action>Labeled '1.2.3.4'</action>
<date>27/09/2013 09:08:00</date>
<comment></comment>
<label>1.2.3.4</label>
<label_comment></label_comment>
<user>John</user>
<shared_links>
<shared_link>$/Beta_1</shared_link>
<shared_link>$/Branches/New_Feature</shared_link>
</shared_links>
</file>
</root>
다음 출력 XML을 생성합니다.
<root>
<file>
<name>file.bat</name>
<vss_path>$/Code/file.bat</vss_path>
<shared_links>
<shared_link>$/Beta_1</shared_link>
</shared_links>
</file>
</root>
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다