使用read a svg file
尝试csv
进入xsl
,但转换为csv后,它包含unnecessary spaces and Cdata information
。
如何从我的csv中删除这些空格和cdata信息。
我正在尝试从xml中只读取标题标签。
以下是我的xsl文件:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text" />
<xsl:strip-space elements="svg"/>
<xsl:template match="//g">
<xsl:text>title</xsl:text>
<xsl:where-populated>
<xsl:choose>
<xsl:when test="title">
<xsl:value-of select="title"/>
</xsl:when>
</xsl:choose>
</xsl:where-populated>
</xsl:template>
</xsl:stylesheet>
我的svg / xml文件:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Generated by Microsoft Visio, SVG Export HR Recruiting Flowchart with data graphics_start.svg Recruiting -->
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:ev="http://www.w3.org/2001/xml-events"
xmlns:v="http://schemas.microsoft.com/visio/2003/SVGExtensions/" width="11in" height="8.5in" viewBox="0 0 792 612"
xml:space="preserve" color-interpolation-filters="sRGB" class="st23">
<v:documentProperties v:langID="1033" v:viewMarkup="false">
<v:userDefs>
<v:ud v:nameU="msvNoAutoConnect" v:val="VT0(0):26"/>
<v:ud v:nameU="msvLastAppliedDataGraphic" v:val="VT4(Data Graphic)"/>
<v:ud v:nameU="msvNoApplyDataGraphicAfterLink" v:val="VT0(1):5"/>
</v:userDefs>
</v:documentProperties>
<style type="text/css">
<![CDATA[
.st1 {visibility:visible}
.st2 {fill:#7efd00;stroke:#443c50;stroke-linecap:round;stroke-linejoin:round;stroke-width:1}
.st3 {fill:#453d51;font-family:Franklin Gothic Book;font-size:0.75em}
.st4 {font-size:1em}
.st5 {stroke:#808080;stroke-linecap:butt;stroke-width:1.5}
.st6 {fill:#2ca0f1}
.st7 {marker-end:url(#mrkr2-19);stroke:#8b8793;stroke-linecap:round;stroke-linejoin:round;stroke-width:1.5}
.st8 {fill:#8b8793;fill-opacity:1;stroke:#8b8793;stroke-opacity:1;stroke-width:0.31645569620253}
.st9 {fill:#fdbe00;stroke:#443c50;stroke-linecap:round;stroke-linejoin:round;stroke-width:1}
.st10 {fill:#7ac943}
.st11 {fill:#00fdfd;stroke:#443c50;stroke-linecap:round;stroke-linejoin:round;stroke-width:1}
.st12 {fill:#fcee21}
.st13 {fill:#00fd40;stroke:#443c50;stroke-linecap:round;stroke-linejoin:round;stroke-width:1}
.st14 {fill:#ff931e}
.st15 {fill:#fd0000;stroke:#43546c;stroke-linecap:round;stroke-linejoin:round;stroke-width:1}
.st16 {fill:#44556e;font-family:Franklin Gothic Book;font-size:0.75em}
.st17 {fill:#ed1c24}
.st18 {fill:#ffffff;stroke:none;stroke-linecap:butt;stroke-width:7.2}
.st19 {fill:#574d66;font-family:Franklin Gothic Book;font-size:0.75em}
.st20 {fill:#eceeea;stroke:#52643d;stroke-linecap:round;stroke-linejoin:round;stroke-width:1}
.st21 {fill:none;stroke:none;stroke-linecap:round;stroke-linejoin:round;stroke-width:1}
.st22 {fill:#453d51;font-family:Franklin Gothic Book;font-size:1.99999em;font-weight:bold}
.st23 {fill:none;fill-rule:evenodd;font-size:12px;overflow:visible;stroke-linecap:square;stroke-miterlimit:3}
]]>
</style>
<defs id="Markers">
<g id="lend2">
<path d="M 1 1 L 0 0 L 1 -1 L 1 1 " style="stroke:none"/>
</g>
<marker id="mrkr2-19" class="st8" v:arrowType="2" v:arrowSize="3" v:setback="3.16" refX="-3.16" orient="auto"
markerUnits="strokeWidth" overflow="visible">
<use xlink:href="#lend2" transform="scale(-3.16,-3.16) "/>
</marker>
</defs>
<g v:mID="0" v:index="1" v:groupContext="foregroundPage">
<v:userDefs>
<v:ud v:nameU="msvDGCalloutGap" v:val="VT0(0.0625):26"/>
<v:ud v:nameU="msvThemeOrder" v:val="VT0(0):26"/>
</v:userDefs>
<title>Recruiting</title>
<v:pageProperties v:drawingScale="1" v:pageScale="1" v:drawingUnits="0" v:shadowOffsetX="9" v:shadowOffsetY="-9"/>
<v:layer v:name="Flowchart" v:index="0"/>
<v:layer v:name="Connector" v:index="1"/>
<v:layer v:name="Data Graphic" v:index="2"/>
<g id="group22-1" transform="translate(198,-436.5)" v:mID="22" v:groupContext="group" v:layerMember="0">
<v:custProps>
<v:cp v:nameU="Cost" v:lbl="Cost" v:prompt="" v:type="7" v:format="@" v:sortKey="" v:invis="false" v:ask="false"
v:langID="1033" v:cal="0"/>
<v:cp v:nameU="ProcessNumber" v:lbl="Process Number" v:prompt="" v:type="2" v:format="" v:sortKey=""
v:invis="false" v:ask="false" v:langID="1033" v:cal="0"/>
<v:cp v:nameU="Owner" v:lbl="Owner" v:prompt="" v:type="0" v:format="" v:sortKey="" v:invis="false" v:ask="false"
v:langID="1033" v:cal="0"/>
<v:cp v:nameU="Function" v:lbl="Function" v:prompt="" v:type="0" v:format="" v:sortKey="" v:invis="false"
v:ask="false" v:langID="1033" v:cal="0" v:val="VT4()"/>
<v:cp v:nameU="StartDate" v:lbl="Start Date" v:prompt="" v:type="5" v:format="" v:sortKey="" v:invis="false"
v:ask="false" v:langID="1033" v:cal="0"/>
<v:cp v:nameU="EndDate" v:lbl="End Date" v:prompt="" v:type="5" v:format="" v:sortKey="" v:invis="false"
v:ask="false" v:langID="1033" v:cal="0"/>
<v:cp v:nameU="Status" v:lbl="Status" v:prompt="" v:type="4"
v:format=";Not Started;In Progress;Completed;Deferred;Waiting on Input" v:sortKey="" v:invis="false"
v:ask="false" v:langID="1033" v:cal="0" v:val="VT4()"/>
<v:cp v:nameU="Cost" v:lbl="" v:prompt="" v:type="0" v:format="" v:sortKey="" v:invis="false" v:ask="false"
v:langID="0" v:cal="0" v:val="VT18(0.0000USD):38"/>
<v:cp v:nameU="ProcessNumber" v:lbl="" v:prompt="" v:type="0" v:format="" v:sortKey="" v:invis="false"
v:ask="false" v:langID="0" v:cal="0" v:val="VT0(101):26"/>
<v:cp v:nameU="Owner" v:lbl="" v:prompt="" v:type="0" v:format="" v:sortKey="" v:invis="false" v:ask="false"
v:langID="0" v:cal="0" v:val="VT4(HR Admin)"/>
<v:cp v:nameU="Function" v:lbl="" v:prompt="" v:type="0" v:format="" v:sortKey="" v:invis="false" v:ask="false"
v:langID="0" v:cal="0" v:val="VT4()"/>
<v:cp v:nameU="StartDate" v:lbl="" v:prompt="" v:type="0" v:format="" v:sortKey="" v:invis="false" v:ask="false"
v:langID="0" v:cal="0" v:val="VT0(0):26"/>
<v:cp v:nameU="EndDate" v:lbl="" v:prompt="" v:type="0" v:format="" v:sortKey="" v:invis="false" v:ask="false"
v:langID="0" v:cal="0" v:val="VT0(0):26"/>
<v:cp v:nameU="Status" v:lbl="" v:prompt="" v:type="0"
v:format=";Not Started;In Progress;Completed;Deferred;Waiting on Input;OK" v:sortKey="" v:invis="false"
v:ask="false" v:langID="0" v:cal="0" v:val="VT4(OK)"/>
<v:cp v:nameU="_VisDM_Displayed_Text" v:lbl="Displayed Text" v:type="0" v:langID="1033"
v:val="VT4(Log hiring request)"/>
<v:cp v:nameU="_VisDM_Risk" v:lbl="Risk" v:type="2" v:langID="1033" v:val="VT0(1):26"/>
</v:custProps>
<v:userDefs>
<v:ud v:nameU="visVersion" v:prompt="" v:val="VT0(15):26"/>
<v:ud v:nameU="DefaultWidth" v:prompt="" v:val="VT0(1):0"/>
<v:ud v:nameU="DefaultHeight" v:prompt="" v:val="VT0(0.75):0"/>
<v:ud v:nameU="ResizeTxtHeight" v:prompt="" v:val="VT0(0.75):0"/>
<v:ud v:nameU="msvLayoutIncludeSubshapes" v:val="VT0(1):5"/>
<v:ud v:nameU="visDGDisplayFormat" v:val="VT0(254):26"/>
<v:ud v:nameU="visDGCBVFill" v:val="VT5(#7efd00)"/>
<v:ud v:nameU="visDGOldColors" v:val="VT0(0):26"/>
</v:userDefs>
<title>Process</title>
<desc>Log hiring request</desc>
<g id="shape22-2" v:mID="22" v:groupContext="groupContent" v:layerMember="0">
<v:textBlock v:margins="rect(2,2,2,2)"/>
<v:textRect cx="36" cy="585" width="72" height="54"/>
<g id="shadow22-3" v:groupContext="shadow" v:shadowOffsetX="0" v:shadowOffsetY="0" v:shadowType="1"
v:shadowScale="0" transform="matrix(1,0,0,1,0,0)" class="st1"/>
<rect x="0" y="558" width="72" height="54" class="st2"/>
<text x="17.49" y="582.3" class="st3" v:langID="1033"><v:paragraph v:horizAlign="1"/><v:tabList/>Log hiring <tspan
x="21.51" dy="1.2em" class="st4">request</tspan>
</text> </g></g>
</svg>
我正在使用的Java代码
String inputSource = INPUT_PATH + FILE_NAME;
StreamSource productXslTransformationFile = new StreamSource(PATH + "root.xsl");
StreamSource xmlInputFile = new StreamSource(INPUT_PATH + FILE_NAME);
StreamResult productMappingOutputFile = new StreamResult(OUTPUT_PATH + FILE_NAME + "_code1.csv");
transfer(xmlInputFile, productXslTransformationFile, productMappingOutputFile, inputSource);
System.out.println("Done!");
我想要的输出
Recruiting
Process
Log hiring request
我是否可以直接从svg文件中读取此标题标记信息,而无需将其转换为xml。