Is XSLT capable of doing this?
Its not the same question I asked before(with the ^^), as this a different one,which as some more noise and uneeded section. Anyway, I have a text file, its contents are:
#HEADER#
Version : 3
EOF : '^'
EOR : '~'
Property Count : 67
Generated Date : 10-March-2011 17:39
#DEFINITION#
AGENT_REF^ADDRESS_1^ADDRESS_2^ADDRESS_3^ADDRESS_4^TOWN^POSTCODE1^POSTCODE2^FEATURE1^FEATURE2^FEATURE3^FEATURE4^FEATURE5^FEATURE6^FEATURE7^FEATURE8^FEATURE9^FEATURE10^SUMMARY^DESCRIPTION^BRANCH_ID^STATUS_ID^BEDROOMS^PRICE^PRICE_QUALIFIE开发者_如何学编程R^PROP_SUB_ID^UPDATE_DATE^CREATE_DATE^DISPLAY_ADDRESS^PUBLISHED_FLAG^LET_DATE_AVAILABLE^LET_BOND^LET_TYPE_ID^LET_FURN_ID^LET_RENT_FREQUENCY^TENURE_TYPE_ID^TRANS_TYPE_ID^NEW_HOME_FLAG^MEDIA_IMAGE_00^MEDIA_IMAGE_TEXT_00^MEDIA_IMAGE_01^MEDIA_IMAGE_TEXT_01^MEDIA_IMAGE_02^MEDIA_IMAGE_TEXT_02^MEDIA_IMAGE_03^MEDIA_IMAGE_TEXT_03^MEDIA_IMAGE_04^MEDIA_IMAGE_TEXT_04^MEDIA_IMAGE_05^MEDIA_IMAGE_TEXT_05^MEDIA_IMAGE_06^MEDIA_IMAGE_TEXT_06^MEDIA_IMAGE_07^MEDIA_IMAGE_TEXT_07^MEDIA_IMAGE_08^MEDIA_IMAGE_TEXT_08^MEDIA_IMAGE_09^MEDIA_IMAGE_TEXT_09^MEDIA_IMAGE_10^MEDIA_IMAGE_TEXT_10^MEDIA_IMAGE_11^MEDIA_IMAGE_TEXT_11^MEDIA_IMAGE_12^MEDIA_IMAGE_TEXT_12^MEDIA_IMAGE_13^MEDIA_IMAGE_TEXT_13^MEDIA_IMAGE_14^MEDIA_IMAGE_TEXT_14^MEDIA_IMAGE_15^MEDIA_IMAGE_TEXT_15^MEDIA_I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12345_ALZ57065V^^Spacious 3 bedroom villa with pool in Vale da Telha^^^^8670-156^^^^^^^^^^^^3 bedrooms villa with pool located in picturesque urbanization of Vale da Telha, on a private corner plot. The villa benefits from all day sun shine. It has a mature settled garden with low maintenance and offers privacy for the villa. The villa comprises of living/dining room with wooden ceiling making the villa very welcoming. It has an open fireplace. The living room leads to the rustic yet modern kitchen, also on to the swimming pool area with BBQ and garden. Three bedrooms all with fitted wardrobes, (1 en suite) and wooden ceilings. All have good sun exposure, light and bright. The...^3 bedrooms villa with pool located in picturesque urbanization of Vale da Telha, on a private corner plot. The villa benefits from all day sun shine. It has a mature settled garden with low maintenance and offers privacy for the villa. The villa comprises of living/dining room with wooden ceiling making the villa very welcoming. It has an open fireplace. The living room leads to the rustic yet modern kitchen, also on to the swimming pool area with BBQ and garden. Three bedrooms all with fitted wardrobes, (1 en suite) and wooden ceilings. All have good sun exposure, light and bright. The detached garage has ample storage space in form of a mezzanine, plumbing for washing machine. Irrigation system. A/C that gives hot and cold air and dehumifies. Good investment for those looking for a permanent home.<br/><br/><br/>^12345^0^3^277000^0^^^^Spacious 3 bedroom villa with pool in Vale da Telha, Aljezur, 8670-156^1^^^^^^^1^N^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^~
12345_A184ALZ^^Lovely 2 bedroom apartment in Aljezur^^^Algarve^^^^^^^^^^^^^Excellent location for this well presented 2 bedroom apartment situated at the entrance of Aljezur. Within walking distance to all the attractions this portuguese village has to offer including many restaurants, shops and just few minutes drive to the fabulous Amoreira beach. The apartment comprises of a spacious lounge/dining room, 2 bedrooms with fitted wardrobes, fully fitted kitchen, bathroom and a possibility to occupy a 55 m2 area of the attic. Apart from the garage in cave there is a parking space provided which is an excellent asset in the summer months. This property is a perfect residental or holiday home as well having great rental potential.^Excellent location for this well presented 2 bedroom apartment situated at the entrance of Aljezur. Within walking distance to all the attractions this portuguese village has to offer including many restaurants, shops and just few minutes drive to the fabulous Amoreira beach. The apartment comprises of a spacious lounge/dining room, 2 bedrooms with fitted wardrobes, fully fitted kitchen, bathroom and a possibility to occupy a 55 m2 area of the attic. Apart from the garage in cave there is a parking space provided which is an excellent asset in the summer months. This property is a perfect residental or holiday home as well having great rental potential.<br/><br/><br/>^12345^0^2^140000^0^^^^Lovely 2 bedroom apartment in Aljezur, Aljezur, Algarve^1^^^^^^^1^N^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^~
Is it possible, using XSLT only(!) to generate an XML file such as:
<POST>
<AGENT_REF>12345_ALZ57065V</AGENT_REF>
<ADDRESS_2>Spacious 3 bedroom villa with pool in Vale da Telha</ADDRESS_2>
...
</POST>
<POST>
<AGENT_REF>12345_A184ALZ</AGENT_REF>
...
</POST>
Basically, using the DEFINITION keywords (splitted by ^) to get the values from the DATA, which when spitted, appears in the same order as the data in the DEFINITION.
Thanks,
Yes, it's possible, use <xsl:analyze-string>
to convert non-XML data to XML.
XSLT is used for transforming XML. Since the first chuck of data you posted is not XML you cannot use XSLT to do this.
If you wanted to go the reverse direction, that would be possible.
UPDATE:
If you are using XSLT 2.0 then refer to @Max Toro answer. Otherwise this is correct.
XSLT 1.0 is for transforming XML to either XML, text or HTML. Therefore the input has to be valid XML. Although this could be technically done in your example by enclosing your input by some root xml tag (e.g. <root>
) and escaping some characters (e.g. <
), this still requires you to to do string parsing in XSLT -- for which XSLT is not designed for. It's not impossible, but it will be really slow (and tedious to write).
You can transform your input file into valid xml first (e.g. with perl,awk,sed,python,...) to yield something like:
<root>
<definition>
<item>AGENT_REF</item>
<item>ADDRESS_1</item>
<item>ADDRESS_2</item>
...
</definition>
<data>
<line>
<item>12345_ALZ57065V</item>
<item/> <!-- important! -->
<item>Spacious 3 bedroom villa with pool in Vale da Telha</item>
<item/>
...
</line>
<line>
...
</line>
...
</data>
</root>
and then transformed that with XSLT to your desired result.
OTOH, when the data is already processed by a string-processing language (like perl), its only a very small additional step to directly generate your desired XML, without using XSLT at all.
精彩评论